gpt4 book ai didi

javascript - 如何在 ngRepeat (AngularJS) 中重复点击处理程序?

转载 作者:行者123 更新时间:2023-12-03 05:33:25 25 4
gpt4 key购买 nike

我遇到以下问题。我想重复菜单链接。但程序不会创建相应的点击处理程序。

查看:

//view is created by Angular Material
<md-menu-item ng-repeat="mItem in ::menuItems">
<md-button ng-click="mItem[action]">
<md-icon>{{ ::mItem.icon }}</md-icon>
{{ ::mItem.name }}
</md-button>
</md-menu-item>

Ctrl:

$scope.menuItems = [
{ icon: 'mode_edit', name: 'Edit', action: 'clickEdit()' },
{ icon: 'delete', name: 'Delete', action: 'clickDelete()' }
];

$scope.clickEdit = clickEdit;
$scope.clickDelete = clickDelete;

function clickEdit() {
$log.info('edit clicked');
}

function clickDelete() {
//code...
}

我需要做什么才能在 ngClick 中获取处理程序?

最佳答案

我认为最好将该逻辑保留在这样的服务中:

//view is created by Angular Material
<md-menu-item ng-repeat="mItem in ::menuItems">
<md-button ng-click="action(mItem.action)">
<md-icon>{{ ::mItem.icon }}</md-icon>
{{ ::mItem.name }}
</md-button>
</md-menu-item>

$scope.menuItems = [
{ icon: 'mode_edit', name: 'Edit', action: 'edit' },
{ icon: 'delete', name: 'Delete', action: 'delete' }
];

$scope.action = function(actionName){
// call service
}

关于javascript - 如何在 ngRepeat (AngularJS) 中重复点击处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40835141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com