Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS uppercase inside the ng-if directive

Tags:

angularjs

Why below one is not working ? I need to convert the IsValue into uppercase value and then need to check it with the NO value.How can I do that ?

   <td class="red-color" ng-if="item.IsValue | uppercase == 'NO'">{{item.IsValue}}</td>
like image 774
Sampath Avatar asked Sep 12 '14 10:09

Sampath


People also ask

How do you uppercase in AngularJS?

uppercase() Function in AngularJS is used to convert the string into uppercase. It can be used when the user wants to show the text in uppercase instead of lowercase. Example: This example illustrates the angular. uppercase() Function by specifying the string is converted into uppercase.

Is uppercase filter in AngularJS?

The uppercase Filter in AngularJS is used to change a string to an uppercase string or letters.

Is ngIf case sensitive?

The star in ngIf is case sensitive. So make sure you spell this exactly the way they are and it was set to a condition.


2 Answers

Make sure 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.

like image 81
Davin Tryon Avatar answered Sep 20 '22 07:09

Davin Tryon


If I understand correctly, you want to check for a value and then display it in uppercase somewhere (?) so this will get you going: the ng-if will just check the value. If it is "test" it will display it as uppercase.

 <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

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

like image 38
alou Avatar answered Sep 22 '22 07:09

alou