0
如何向角度對象添加一個動態的onclick或click事件函數?爲角度對象添加動態功能
添加的onclick = {{item.function}}或NG單擊= {{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>
不工作演示 http://codepen.io/anon/pen/jqEKRP