想在给定的时间间隔后动态地打印字母,错误:[$ rootScope:infdig] 10 $ digest()迭代到达。中止(...)

var str = "get_data_httpaja.php?un=" + $scope.uName; 

var avail=["a","v","a","i","l","a","b","l","e"];

var i=0;

$http.get(str).then(function (dt) {

alert(dt.data);

// $scope.uPlace = dt.data;

if(dt.data==0){

var myvar=$window.setInterval(function() {

$scope.$watch("uAvailable",function (nv,ov) {

$scope.uAvailable+=avail[i];

})

i++;

},500)

if(i>8)$window.clearInterval(myvar);

}

}

我取出由服务器的结果,以后如果result==0然后我想打印的字母“可用”动态信,但收到错误:(

回答:

这里是一个有效的解决方案:

var myApp = angular.module('myApp',[]); 

myApp.controller('MyCtrl', MyCtrl);

function MyCtrl($scope,$timeout,$interval) {

$scope.uAvailable = '';

$timeout(function(){},500).then(function() {

var avail=["a","v","a","i","l","a","b","l","e"];

$interval(function(counter){

$scope.uAvailable += avail[--counter];

}, 500, avail.length);

});

}

我用$超时而不是$ HTTP,因为这两个返回的承诺(这只是这个例子的目的)

的jsfiddle:http://jsfiddle.net/obkx9zaz/

以上是 想在给定的时间间隔后动态地打印字母,错误:[$ rootScope:infdig] 10 $ digest()迭代到达。中止(...) 的全部内容, 来源链接: utcz.com/qa/259810.html

回到顶部