FranzHuber23 FranzHuber23 - 1 year ago 90
AngularJS Question

AngularJS open Link if condition

I want to check an if condition inside an href in AngularJS:

<a class="button button-block" href="if(cond){#/app/abc}else{nothing}" ng-click="doSomething()">Suchen</a>

where cond is a condition that can be true or false and the link shall only be openend if this condition is fullfilled.

Does anyone know if this is possible and if yes how?


You could have something like below in which it will create a href with URL when cond is true, otherwise it will create a blank href which would not redirect to anywhere.

ng-href="{{cond? '#/app/abc': ''}}"

Otherwise do remove href from anchor tag, and handle redirect logic from ng-click's doSomething function itself with the help of $location.path('#/app/abc') for redirection.