0

How can I do this without the multiple ng-ifs?

<h3 ng-if="data.link"><a href="{{data.link}}">{{data.name}}</a></h3>
<h3 ng-if="!data.link"><em>{{data.name}}</em></h3>

I've also considered ng-switch, but that requires an extra container element which I don't like.

Also tried tertiary expressions (e.g. {{data.link?'option 1':'option 2'}}) but that looks messy and it doesn't do well with HTML. ng-bind-template escapes HTML chars and also looks messy.

What's the best way to do this?

Francisc
  • 77,430
  • 63
  • 180
  • 276
  • i think there is no way. take a look: http://stackoverflow.com/questions/15810278/if-else-in-angularjs-template – ariel Jan 16 '14 at 11:57
  • Thanks, ariel. You're probably right and there's no better way to mimic if-else. – Francisc Jan 16 '14 at 12:11
  • if you are looking for a reusable element that can do this for multiple elements, you could always use a directive that encapsulates the logic – Claies Jan 16 '14 at 12:42

0 Answers0