作者:广东工业大学普通话_333 | 来源:互联网 | 2023-01-26 17:00
Hereiaddadelayinjavascriptforloopusing$timeout.UnexpectedlyigotanerrorsayingReferen
Here i add a delay in Javascript forloop using $timeout. Unexpectedly i got an error saying
ReferenceError $timeout is not defined. i am new to angularjs please help me. PLNKR
在这里,我使用$ timeout在Javascript forloop中添加延迟。出乎意料的是我得到一个错误,说没有定义ReferenceError $ timeout。我是angularjs的新手,请帮助我。 PLNKR
function CompLibrary() {
return {
init: init
}
function init(dependencies, controller) {
dependencies.push(controller);
angularApp.controller('MainCtrl', dependencies);
}
}
var compX = CompLibrary();
compX.init(deps, _controller);
function _controller() {
var ViewModel = this;
ViewModel.search = "Name";
ViewModel.quantity = 1;
for(var i = 0; i <4; i++) {
(function(i){
$timeout(function() {
ViewModel.quantity++;
}, i * 2000);
})(i); // Pass in i here
}
}
2 个解决方案