189
rated 0 times
[
190]
[
1]
/ answers: 1 / hits: 27318
/ 8 Years ago, wed, march 30, 2016, 12:00:00
I want to set the id attribute of a HTML element conditionally.
Simple way:
<!-- expression = true -->
<div ng-if=expression>
<a href id=this-one>Anchor with id</a>
</div>
<div ng-if=!expression>
<a href>Anchor without id</a>
</div>
output-if-expression-true = <a href id=this-one>Anchor with id</a>
output-if-expression-false= <a href>Anchor without id</a>
Can I avoid this with something like a ternary operator ? for example ...
<a href ng-attr-id={{expresion ? 'this-one': ''}}>Anchor</a>
More From » angularjs