AngularJS uppercase inside ng-if directive

Why does one below not work? I need to convert the IsValue value to the top, and then I need to check it with the NO value. How can i do this?

  <td class="red-color" ng-if="item.IsValue | uppercase == 'NO'">{{item.IsValue}}</td> 
+6
source share
3 answers

Ensure that the uppercase filter is applied (using () ) before comparing the value:

 <td class="red-color" ng-if="(item.IsValue | uppercase) == 'NO'">{{item.IsValue}}</td> 

Here is a working plunker .

+13
source

If I understand correctly, you want to check the value and then display it in uppercase somewhere (?) So that it gets: ng-if will just check the value. If it is a β€œtest”, it will display it as a capital letter.

  <div ng-controller="MyCtrl"> <p class="red-color" ng-if="item.IsValue == 'test'">{{item.IsValue | uppercase}}</p> <input ng-model="item.IsValue" type="text"> </div> 

Js

  function MyCtrl($scope) { $scope.item = {IsValue: 'UpPerCASE'}; } 

demo

string comparison is case-sensitive, so if you want to convert it and then compare, you must enter a string. toUppeCcase () or use the angular method

+1
source

AngularJS accepts any word value starting with 'n' or 'N' as false. You do not need to convert uppercase letters and check the value if the value of your model changes "no", "yes".

 <td class="red-color" ng-if="item.IsValue">{{item.IsValue}}</td> 

can work in many cases.

0
source

Source: https://habr.com/ru/post/975183/


All Articles