简体   繁体   English

使用模态时为控制器中的ng-click定义动态角度函数

[英]Define a dynamic angular function for ng-click in controller when using a modal

How can I define a function that executes on ng-click in a modal? 如何定义在模态中按ng-click执行的函数?

I tried this: 我尝试了这个:

<a ng-click="action.func(attr);">{{action.name}}</a></li> 

And in the controller: 并在控制器中:

$scope.attributeActions = [{name: 'remove', func: $scope.remove()}];

The remove function is executing onLoad of the modal form. remove函数正在执行模态形式的onLoad。

I got it working. 我知道了

In the form: 形式:

<li ng-repeat="action in attributeActions>
<a ng-click="execute(action.func, attr);">{{action.name}}</a></li>

In the controller: 在控制器中:

$scope.remove = function(attr) { 
    console.log('it worked', attr);
};

$scope.attributeActions = [{name: 'remove', func: $scope.remove}];

$scope.execute = function(fn, attr) {
    console.log('executing function', fn);
    fn(attr);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM