禁用ng-单击所有类型元素的某些应用条件

时间:2022-08-25 23:32:06

In my application I've binded several elements with ng-click directive like below

在我的应用程序中,我使用ng-click指令绑定了几个元素,如下所示

<a ng-click="DoSomething()"/>
<button ng-click="DoSomethingElse()">xyz</button>
<span ng-click="DoSomething()"></span>

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

现在我的应用程序在某些情况下我希望发生ng-click的默认行为,但在某些情况下我想完全禁用要调用的回调函数(DoSomething(),DoSomethingElse()..)。

For checking this scenarios I've one scope variable say $scope.IsClickEnable = true/false;

为了检查这种情况,我有一个范围变量说$ scope.IsClickEnable = true / false;

So how can I accomplish this kind of behaviour?

那么我怎样才能完成这种行为呢?

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-disable来禁用元素,但它只适用于按钮类型的元素,因此在我的场景中不起作用

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

我还可以检查每个函数调用中的条件,但我想通过覆盖ng-click行为或其他东西来实现这一目标。

1 个解决方案

#1


67  

Do like this:

这样做:

<button ng-click="!IsClickEnable||DoSomethingElse()">xyz</button>

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

当IsClickEnable的值为true时,将在按钮单击时调用该函数,然后将调用函数'DoSomethingElse()',否则将不会调用它

#1


67  

Do like this:

这样做:

<button ng-click="!IsClickEnable||DoSomethingElse()">xyz</button>

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

当IsClickEnable的值为true时,将在按钮单击时调用该函数,然后将调用函数'DoSomethingElse()',否则将不会调用它