AngularJS:清除 $watch [英] AngularJS : Clear $watch

查看:25
本文介绍了AngularJS:清除 $watch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 AngularJS 应用程序中有一个监视功能.

I have a watch function in my AngularJS application.

$scope.$watch('quartzCrystal', function () {
   ...
}

但是,在某些情况下(在我的示例中,在我的单页应用程序中更改页面)我想要停止那个手表(就像清除超时一样).

However, after some condition (in my example, changing the page at my single-page application) I want to stop that watch (as like clearing timeout).

我该怎么做?

推荐答案

$watch 返回一个注销函数.调用它会注销 $watcher.

$watch returns a deregistration function. Calling it would deregister the $watcher.

var listener = $scope.$watch("quartz", function () {});
// ...
listener(); // Would clear the watch

这篇关于AngularJS:清除 $watch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆