如何停止$看着AngularJS? [英] How do I stop $watching in AngularJS?
本文介绍了如何停止$看着AngularJS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以成立一个$上观看AngularJS范围时前pression我感兴趣的是已经改变的通知。但我怎么驻足观看,一旦我失去了兴趣?
I can set up a $watch on an AngularJS scope to be notified when the expression I am interested in has changed. But how do I stop watching once I lose interest?
推荐答案
致电时 $观看
返回一个函数,注销绑定前pression。
When calling $watch
a function is returned that unregisters the bound expression.
例如,观看变量富
只换一次:
E.g., to watch a variable foo
only change once:
var unregister = $scope.$watch('foo', function () {
// Do something interesting here ...
unregister();
});
希望有所帮助: - )
Hope that helps :-)
这篇关于如何停止$看着AngularJS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文