I want to set the id attribute of an HTML element conditionally.
A simple way:
<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>
Is it possible to avoid this with the help of a three-dimensional operator? eg...
<a href ng-attr-id="{{expresion ? 'this-one': ''}}">Anchor</a>
source
share