3

This is the html file and the code

<ul class="list">
    <li id="numword" data-score="{{item.score}}" class="" ng-repeat="item in words track by $index">
        {{item.word}} {{item.score}}
    </li>
</ul>

This is how it looks in html

<li>nice 0.4</li>
<li>sad -0.2</li>
<li>modest 0</li>

This is the js file in angular

$http.get('select.php') .success(function(data){ $scope.words = data; })

This is the database

I have value of words and scores, every word has own score that is in number

My question is: data-score="{{item.score}}" i got values of 0.4, 0.2, -0.1, 0...

I need to check if value is greater than 0, equal to 0 and less to 0 in order to add classes to li.

How can i do that ?

1
  • Not sure who down-voted or why exactly but making the description and tags more relevant would help, this question doesn't really have anything to do with PHP you just happen to have a service that is written in PHP but that doesn't affect the angular functionality in any way (one is server side the other is client side, don't mix the two) Commented Jul 19, 2016 at 21:31

1 Answer 1

4

You need ngClass attribute for this:

ng-class="{positive: item.score > 0, negative: item.score < 0}"

This directive is using an object, with property as the class and value as the condition. If the condition is true, then the class (which is the property) will be added to the element.

Read more about ngClass here: https://docs.angularjs.org/api/ng/directive/ngClass

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.