【发布时间】:2014-10-18 10:57:17
【问题描述】:
我正在尝试在抽象状态中定义一个控制器,以便我可以为所有视图使用一个控制器,但如果控制器是在外部定义的,则不会调用控制器内部的函数。
.state('update', {
url : '/update',
abstract: true,
template: '<ui-view/>',
controller : function($scope) { //works
$scope.hello = function() {
alert("hello");
}
}
controller : 'updateController' // Doesn't work
})
.state('update.detail', {
url : '/view/:id',
views : {
"" : {
templateUrl : 'update-detail.html'
},
"header@update.detail" : {
templateUrl : 'header.html'
},
"genericnavigation@update.detail" : {
templateUrl : 'generic-navigation.html'
},
"mnavigation@update.detail" : {
templateUrl : 'mobile-navigation.html'
},
"updatecontent@update.detail" : {
templateUrl : 'update-content.html'
}
}
})
HTML
header.html
<div ng-click="hello();"></div> //Click event doesn't get fired for ( controller : 'updateController' )
app.controller('updateController', ['$scope', '$state', function($state, $scope) {
console.log("inside update")
$scope.hello = function() {
alert("hello");
}
}]);
【问题讨论】:
标签: angularjs angular-ui angular-ui-router