Reputation: 1688
I have a conditional ng-click through which i would like to call multiple methods:
<a ng-click="!flag || (setFirst(section); setSecond(section);)">
Unfortunately this will not work. But is there a way in which i can wrap these 2 calls together ?
I know that the following approach will work, but i don't to do the check for every single method i'll call
<a ng-click="!flag || setFirst(section); !flag || setSecond(section);">
The sample code is available here: http://jsfiddle.net/tLtur9tj/1/
Thanks
Upvotes: 0
Views: 214
Reputation: 4563
Try this:
<a ng-click="!flag || (setFirst(section) || setSecond(section))">
But I recommend not using such logic in your template. You really should consider putting it in your controller, e.g.:
HTML:
<a ng-click="setSections(flag)">
Controller:
var setSections = function(flag) {
if(!flag) {
setFirst(section);
setSecond(section);
}
}
Upvotes: 2
Reputation: 3644
Assuming your methods dont return anything:
flag || (func_1() || func_2())
should do the trick
Upvotes: 1