angular.js事件发出,可变加载时间

时间:2015-02-23 19:44:13

标签: angularjs

我有这两个控制器:

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秒。为什么呢?

1 个答案:

答案 0 :(得分:0)

通过调用$scope.$apply();来解决问题。