Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs if statements?

So I'm running through the tutorial for AngularJS:

I have an array defined in the controller and i'm returning different points in the array by calling when i'm looping through ng-repeat {{feature.name}} {{feature.description}}

What i don't understand is lets say i have a third point in the array called "importance" and it's a number from 1 to 10. I don't want to display that number in the html but what i do want to do is apply a different color to the feature if that "importance" number in the array is 10 vs 1

so how do i write an if statement to do this:

i.e.

<p style="**insert if statement: {{if feature.importance == 10}} color:red; {{/if}} **">{{feature.description}}</p>

no idea if that's right but that's what i want to do

like image 965
btm1 Avatar asked Oct 01 '12 00:10

btm1


1 Answers

I do not think there is if statement available. For your styling purpose, ng-class can be used.

<p ng-class="{important: feature.importance == 10 }">

ng-switch is also convenient.

-- update --

take a look at: https://stackoverflow.com/a/18021855/1238847

angular1.2.0RC seems to have ng-if support.

like image 200
Tosh Avatar answered Sep 29 '22 12:09

Tosh