我已经写了这个应用程序
http://plnkr.co/edit/pXUCkT?p=info
在这里,我尝试从我的angular指令内的ng-click事件中调用在父控制器中定义的方法
var app = angular.module('ExampleApp2', ['ngRoute']);
app.config(function($routeProvider){
$routeProvider
.when('/page1', {templateUrl: 'page1.html', controller: 'page1Controller'})
});
app.directive('sidebar', function() {
return {
restrict: 'E',
scope: {
items: '=',
onclick: '&'
},
templateUrl: 'menu.html'
};
});
app.controller('page1Controller', function($scope){
$scope.currentselection=3;
$scope.items = [{tname: 'test1', sel: 1}, {tname: 'test2', sel: 2}, {tname: 'test3', sel: 3}];
$scope.onclick = function(i) {
alert(i);
};
});
此方法已成功调用...但是参数未定义。为什么我无法通过参数?
你的混蛋不工作。我可以建议尝试像这样在模板中调用方法
onclick({i:item.sel})
或者 onclick(item.sel)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句