AngularJS值无法改变的setTimeout [英] AngularJS value won't change with setTimeout
本文介绍了AngularJS值无法改变的setTimeout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想换一个范围的变量在页面初始化之后。
我有以下code角一个应用程序:
I wanted to change a scope variable after the page has been initialized. I have a angular application with following code:
$scope.names = ['Jack'];
append_name = function(){$scope.names.push('Bob');}
setTimeout(append_name, 2000);
艰难我没有看到指定的延迟后的值的变化。
这里是plunker http://plnkr.co/edit/FBa2fwb7js8pRNENNJof
推荐答案
简短的回答:使用内置的 $超时
服务,而不是的setTimeout
:
http://plnkr.co/edit/nh1jEhocRpXtD0rUTh4k?p=$p$pview一>
Short answer: use the built-in $timeout
service instead of setTimeout
:
http://plnkr.co/edit/nh1jEhocRpXtD0rUTh4k?p=preview
龙答案就在这里: http://stackoverflow.com/a/9693933/1418796
这篇关于AngularJS值无法改变的setTimeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文