$scope.runTest = function() {
var statesArray = ['Running', 'Complete', 'Rejected'];
var rand = statesArray[Math.floor(Math.random() * statesArray.length)];
item.state = 'Running';
console.log(rand)
window.setTimeout(function() {
item.state = rand;
}, 6000);
};
item
状态更改为 Running
成功,但此后状态不会更改为 window.setTimeout
中所述的随机状态功能。
我哪里错了?
最佳答案
你应该使用 Angular $timeout
service
$timeout(function() {
item.state = rand;
}, 6000);
关于javascript - AngularJS:如何将 window.setTimeout 插入范围函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34361053/