javascript - How to change text in this case using ng-if or other expression? -


i'm trying change text in title tag based on tag's direction value:

<li ng-repeat="t in tags">     <div class="tag"          ng-class="{'green-up': t.direction == 'positive',                     'red-down': t.direction == 'negative',                     ''        : t.direction == 'stagnant'}"                     title="percentage increase"                     ng-if="">{{t.name}}</div> </li> 

the direction either positive, negative or stagnant, should correspond title="percentage increase" title="percentage decrease" or title="percentage"

what angular syntax best used in case?

why not set tag settings object

$scope.taginfo = {     positive:{ class:"green-up", title:"percentage increase" },     negative:{ class:"red-down", title:"percentage decrease" } } 

and call in ng-repeat

<div class="tag"      ng-class="taginfo[t.direction].class"      title="{{taginfo[t.direction].title}}">{{t.name}}</div> 

http://jsfiddle.net/rlrh0lr1/

if absolutely positively must use conditional clause rather mapping lookup, call method f.e title="{{gettitle(t.direction)}}

$scope.gettitle = function(direction) {     if (direction==="positive") {         return "increase";     } else if (direction==="negative") {         return "decrease";     } }; 

http://jsfiddle.net/p6aysky5/

i don't see point @ of doing though. contributes making code messier.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -