2014-09-29 14 views
8

Chcę ustawić atrybut title, jeśli pewien warunek jest prawdziwy. Jeśli treść jest avaiblabe, chcę ustawić klasę i tekst alternatywny. Jak mogę ustawić tekst tytułu?AngularJS - Ustaw atrybut tytułu

HTML

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

Odpowiedz

4

użyć wyrażenia jak ten {{ condition && if_true || if_false }}. Przykład:

<li ng-class="{ 'my_class': !!content }" title="{{ !!content && content || otherContent }}"> 
+0

Dlaczego dwa '!!', to nie dla mnie. – user1477955

+0

Sprawdź to [odpowiedź] (http://stackoverflow.com/a/784946) ... – bmleite

+2

Dlaczego '&&' i '||'? '? ..: .. 'jest prostsze, prawda? – robert4

Powiązane problemy