9

I want to set an title attribute if a certain a condition is true. If content is avaiblabe I want to set a class and the alt text. How can I set the title text?

HTML

<li ng-class="{true: 'my_class', false: ''}[content]"  title="this is content">  
user1477955
  • 1,552
  • 6
  • 21
  • 34

2 Answers2

8

You can use same technique as you used for the ng-class:

<li ng-class="{true: 'my_class', false: ''}[content]"  title="{{{true: 'title true', false: 'title false'}[content]}}">

http://plnkr.co/edit/IdBxje8PUMPEK3MnenXt?p=preview

Marian Ban
  • 8,020
  • 1
  • 30
  • 45
4

Use an expression like this {{ condition && if_true || if_false }}. Example:

<li ng-class="{ 'my_class': !!content }" title="{{ !!content && content || otherContent }}">
bmleite
  • 26,700
  • 4
  • 69
  • 46