angularjs - How to do a logic operation in Angular Template -
all:
i wonder how can set or operator on html string in angualar template, like:
<div>{{value || <h6>no header now.</h6>}}</div>
the logic if value string not undefined, show value text, otherwise show error "no header now" wrapped <h6>
.
i not know why expression can not correctly interpreted?
thanks
this can solved ng-if
:
<div ng-if="value">value</div> <div ng-if="!value"><h6>no header now.</h6></div>
you can add specific attributes (e.g. class
) and/or directives (e.g. ng-click
) on each <div>
.
the problem using single element have repeat condition several times:
<div ng-class="{ value: 'class1', !value: 'class2' }" ng-click="value ? action1() : action2()" ng-bind-html="value || html"> </div>
Comments
Post a Comment