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>
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..
For checking this scenarios I've one scope variable say $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
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..
The ng-disabled directive sets the disabled attribute of a form field (input, select, or textarea). The form field will be disabled if the expression inside the ng-disabled attribute returns true. The ng-disabled directive is necessary to be able to shift the value between true and false .
Another significant difference between ng-click and onclick is the execution context. Code inside an onclick attribute executes against the global window object, while an expression inside of ng-click executes against a specific scope object, typically the scope object representing the model for the current controller.
For a single btn, it's ok to use ng-click or onclick in the ng-app . There is no difference between the two functions. For effective team work, you,d better to have an account with each other. In Angular apps, ng-click is recommended.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With