user818700
user818700

Reputation:

Inline if statement inside ng-click to run one of two functions

Is is possible to have something like:

<div ng-click="someVar == '1' ? functionOne() : functionTwo() ">
  Click me!
</div>

So depending what someVar is, ng-click would either run functionOne or functionTwo.

Upvotes: 0

Views: 3963

Answers (2)

Disha
Disha

Reputation: 832

yes, you can do it.

<div ng-click="obj.length>1  ? functionOne() : functionTwo() ">
   Click me!
</div>

Upvotes: 0

Alex
Alex

Reputation: 23300

I suggest creating "handlers" for this:

<div ng-click="functionThree(someVar)">
  Click me!
</div>

function functionThree(someVar){
    someVar == '1' ? functionOne() : functionTwo(); 
}

Upvotes: 3

Related Questions