Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

javascript - AngularJS:清除$ watch(AngularJS : Clear $watch)

I have a watch function in my AngularJS application.

(我的AngularJS应用程序中有一个watch功能。)

$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).

(但是,在某些条件之后(在我的例子中,在我的单页应用程序中更改页面 )我想要停止该监视(就像清除超时一样)。)

How can I do that?

(我怎样才能做到这一点?)

  ask by kamaci translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

$watch returns a deregistration function.

($watch返回注销功能。)

Calling it would deregister the $watcher .

(调用它会取消注册$watcher 。)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...