Growler Growler - 1 year ago 201
AngularJS Question

Angular ternary with html

How can I include html in a ternary operator?

{{ (q.result === 1) ? "<i class="fa fa-check" aria-hidden="true"></i>" ? "<i class="fa fa-times" aria-hidden="true"></i>" }}

If not possible, I guess the obvious alternative is to do two wrapping element blocks with
<div ng-if="result">HTML</div>
<div ng-if="!result">OTHER HTML</div>

Answer Source

You can acccomplish what you want with ng-class. It actually supports the ternary operator

<i class="fa" aria-hidden="true" ng-class"(q.result === 1) ? 'fa-check' : 'fa-times'"></i>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download