Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular JS | what to pass in ng-click ternary operator to do nothing

I am trying to enable ng-click based on a condition using ternary operator (?:)

ng-click="hasPermission?Update():...."

In last parameter of ternary operator what can I pass so that nothing would happen.

Also, I don't want to create any dummy function in my JS or to write any irrelevant condition as 1=1

like image 526
Vick Avatar asked Aug 13 '14 06:08

Vick


2 Answers

angular.noop() was provided to address your scenario:

<div ng-click="hasPermission ? Update() : angular.noop()">

noop() is a function that peforms no operations.

Documention Here

like image 127
pixelbits Avatar answered Oct 02 '22 00:10

pixelbits


You can do it like this instead:

ng-click="hasPermission && Update()"
like image 35
ryeballar Avatar answered Oct 02 '22 00:10

ryeballar