我有这两个控制器:
app.controller('SomeCtrl', ['$scope', '$rootScope', function($scope, $rootScope){
$scope.number = 0;
$rootScope.$on('do', function(event, data) {
$scope.number += data;
});
}]);
app.controller('SecondCtrl', ['$scope', function($scope) {
this.something = function() {
$scope.$emit('do', 5);
};
}]);
在html中我只是写这个变量:
<div ng-controller="SomeCtrl">{{number}}</div>
当我调用something
函数时,它会发出do
。但它正在更新数字,如10秒。为什么呢?
答案 0 :(得分:0)
通过调用$scope.$apply();
来解决问题。