本文介紹了調用后在 angularjs 中解綁 $watch的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我知道你可以像這樣解除 $watch 的綁定:
I know you can unbind a $watch like this:
var listener = $scope.$watch("tag", function () {});
// ...
listener(); // would clear the watch
但是你可以在 watch 函數聲明中取消綁定手表嗎?那么在手表執行一次之后,它會自行解除綁定嗎?比如:
but can you unbind the watch within the watch function declaration. So after the watch gets executed once, it unbinds itself? Something like:
$scope.$watch("tag", function () {
unbindme()
});
推薦答案
你可以像你已經做的那樣做,在你的函數中調用取消注冊":
you can just do it the same way you already do, call the "deregistration" inside your function:
var unbind = $scope.$watch("tag", function () {
// ...
unbind();
});
這篇關于調用后在 angularjs 中解綁 $watch的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!