【发布时间】:2013-07-20 11:06:01
【问题描述】:
我有以下设置:
stApp.controller('AdminTableController', ['$rootScope', '$scope', 'gridService',
function ($rootScope, $scope, gridService) {
$scope.$watch('tableData.$pristine', function (newValue) {
$rootScope.broadcast("tableDataUpdated", {
state: page.$pristine
});
});
}])
stApp.controller('AdminGridController', ['$rootScope', '$scope', 'gridService',
function ($rootScope, $scope, gridService) {
$rootScope.on("tableDataUpdated", function (args) {
//args.state would have the state.
alert(args.state);
});
}])
当我运行此代码时,我收到一条消息:
Object #<Object> has no method 'on'
请注意,我对 $rootScope.on 和 $scope.on 都进行了尝试
【问题讨论】:
-
其实你需要用'$on'代替'on'和$broadcast代替broadcast
标签: javascript angularjs