问题描述
我有模式,我看这个模型的一些变化,在$绑定的手表功能。我有绑定到ngClick,谁改变模型的功能。我需要能够在ngClick prevent模型的侦听器调用,因为我不想要的轨道改变,但如果模型一些其他的方式改变,除了ngClick绑定功能,我想监听工作。
但我并不想解除听众,我只是希望它停止执行本目前的时刻。
例如:
$ scope.AlertIfChange =功能(){
警报('模式的变革!');
};$ scope.watch(型号,AlertIfChange,真正的);$ scope.clickHandler =功能(){
$ scope.model =点击通过改变;
- 有些东西prevent AlertIfChange调用 -
};
如果您需要在很多地方这个功能,考虑写这就像NG单击,但不会触发回调,直到特定的条件指令得到满足。
I have model, and I watch this model for some changes with functions binded in $watch. And I have function binded to ngClick, who change model. I need to be able to prevent model listener invocation in ngClick, because I don't want track that changes, but if model changed with some other way, except ngClick binded function, I want listeners work.
But I don't want to unbind listeners, I just want it to stop execution for this current moment.
example:
$scope.AlertIfChange = function(){
alert('model changes!');
};
$scope.watch(model, AlertIfChange, true);
$scope.clickHandler = function(){
$scope.model = "changed by click";
-- some stuff to prevent AlertIfChange invocation --
};
If you need this functionality in a lot of places, consider writing a directive which works like ng-click, but doesn't trigger the callback until a specific condition is met.
这篇关于如何prevent模型的变化侦听(以$手表绑定)调用的角度ngClick函数内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!