[英]Adding function dynamical to angular objects
如何為動態對象添加功能到onclick或click事件?
添加onclick = {{item.function}}或ng-click = {{item.function}}無效
JS
angular
.module('app', [])
.controller('MainController', ['$scope', function($scope) {
$scope.test = function() {
alert(1);
};
$scope.items = {
'item1': {
name: 'Item1',
function: 'test()' // Not calling
}
};
}]);
HTML
<html ng-app="app">
<body ng-controller="MainController">
<ul ng-repeat="item in items">
<li ng-bind="item.name" ng-click="item.function"></li>
</ul>
</body>
</html>
在控制器中:
...
'item1': {
name: 'Item1',
f: $scope.test
}
...
在模板中:
<li ng-bind="item.name" ng-click="item.f()"></li>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.