0
在我的控制器中,我有: var timespanServiceFn;
timespanServiceFn = function() {
return timespanService.getTimespan();
};
$scope.$watch(timespanServiceFn, $scope.updateVolume());
我$scope.updateVolume()
功能只是有一个console.log
,让我知道我到了那里。
我timespanService
也是超级简单:
myApp.service('timespanService', [
'$http', '$q', function($http, $q) {
var currentTimespan;
currentTimespan = '3M';
this.getTimespan = function() {
return currentTimespan;
};
this.setTimespan = function(timespan) {
console.log('setting timespan to', timespan);
return currentTimespan = timespan;
};
}
]);
那么,为什么当我改变了时间跨度中,$watch
不会被触发?