5

The following conditional return false inside a angular view:

<a ng-class="(parseFloat('-0.56%') < 0) ? 'true' : 'false'">...</a>

I've already added the parseFloat method in $scope.

$scope.parseFloat = parseFloat;

Thanks for any help.

3
  • No, there is no asterisks, my mistake posting the question. Commented May 23, 2014 at 19:50
  • What is your intended output? to have either the class true or false? Commented May 23, 2014 at 19:51
  • The intent is to have different classes depending if a value is bigger than zero. Commented May 23, 2014 at 19:54

1 Answer 1

5

Take a look at this fiddle

You can use option 1 (as you have it) but you need to use class not ng-class

<a class="{{(parseFloat('-0.56%') < 0) ? 'true1' : 'false'}}">Option 1</a>

In order to use ng-class use this:

<a ng-class="{'true': (parseFloat('-0.56%') < 0), 'false': (parseFloat('-0.56%') >= 0)}">Option 2a</a>    
<a ng-class="{'true': (parseFloat('0.56%') < 0), 'false': (parseFloat('0.56%') >= 0)}">Option 2b</a>

The difference being is that ng-class takes an object where the key is the class and the value is the boolean evaluation to determine if the class gets added to the element.

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.