【发布时间】:2016-06-30 00:02:47
【问题描述】:
我有以下服务:
App.service('DateTimeService',function($timeout,$rootScope)
{
var rootThis = this;
this.countUp = function() {
DateTime1 = new Date();
console.log(DateTime1);
$timeout(rootThis.countUp, 5000);
$rootScope.DateTime = DateTime1;
}
$timeout(rootThis.countUp, 5000);
})
这已经被注入到控制器中:
var aController = function($scope, $rootScope, $location, $http,DateTimeService)
{
}
我在 angularJs 视图中定义了以下内容:
<span id="datetime">{{DateTime}}</span>
现在当我运行这个程序时,这个 DateTime 会自动更新到视图中,因为 $rootScope.DateTime 在递归调用中自动更新到 DateTimeService 中。
怎么会?,但是我尝试并搜索了很多方法,以便可以在 AngularJs Scope 中更新服务中某些 $rootScope 变量的动态更新值,然后查看? (但我没有找到任何东西?),现在当我通过调用此函数在 DateTime 服务中运行该函数时: $timeout(rootThis.countUp, 5000);然后它会更新视图的值?
【问题讨论】:
标签: angularjs