问题描述
在我的申请,我与绑定NG-点击指令几个元素像下面
In my application I've binded several elements with ng-click directive like below
<a ng-click="DoSomething()"/>
<button ng-click="DoSomethingElse()">xyz</button>
<span ng-click="DoSomething()"></span>
现在我在某些情况下的应用我想的默认行为NG-点击的情况发生,但在某些情况下我想完全禁用回调函数(DoSomething的(),DoSomethingElse()..)被称为..
Now in my application in certain scenarios I want default behavior of ng-click to happen, but in certain scenarios I want to completely disable the callback function(DoSomething(), DoSomethingElse()..) to be called..
有关检查这个场景我一个作用域变量说 $ scope.IsClickEnable = TRUE / FALSE;
For checking this scenarios I've one scope variable say $scope.IsClickEnable = true/false;
那么,如何才能做到这一点样的行为?
So how can I accomplish this kind of behaviour?
我可以用NG-禁止禁用元素,但它只会在按键种元素的工作,这样就不会在我的情况下工作。
I can use ng-disable to disable elements but it will only work on button kind of elements, so that will not work in my scenario
我也可以检查每个函数调用的条件,但我想更具体的方式通过覆盖NG-点击行为或东西来完成这个..
And I can also check conditions in every function call but I want more specific way to accomplish this by overriding ng-click behavior or something..
推荐答案
这样做:
<button ng-click="!IsClickEnable||DoSomethingElse()">xyz</button>
在IsClickEnable的价值为真,那么函数将被调用按钮点击则函数'DoSomethingElse()将被调用要不然也不会被调用。
when the value of IsClickEnable is true then the function will be called on the button click then the function 'DoSomethingElse()' will be called else it will not get called
这篇关于对所有类型的元件的应用的特定条件下禁用纳克单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!