在所有类型元素的某些应用条件上禁用 ng-click [英] Disable ng-click on certain conditions of application for all types of element

查看:19
本文介绍了在所有类型元素的某些应用条件上禁用 ng-click的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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-click 的默认行为,但在某些情况下,我想完全禁用回调函数(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-disable 来禁用元素,但它只适用于按钮类型的元素,因此在我的场景中不起作用

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-click 行为或其他方式来实现此目的的更具体方法..

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 的值为 true 时,将在单击按钮时调用该函数,然后将调用函数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

这篇关于在所有类型元素的某些应用条件上禁用 ng-click的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆