Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tolowercase string Angular

Very simple issue I cant seem to resolve, my markup

<select class="testing" ng-model="Car_name"  ng-options="item in categories['Car_name']">

I'm trying to change 'Car_name' to be 'car_name' however the server populated the ng-model & categories[] entries, so I'm not sure how I can watch and convert to lowercase in my controller.

If I could do

{{Car_name|lowercase}} 

would be the easiest, but not sure on the format.

like image 519
Poiro Avatar asked Jul 13 '15 12:07

Poiro


People also ask

What does toLowerCase () method do in JavaScript?

The toLowerCase () method converts a string to lowercase letters. The toLowerCase () method does not change the original string. The string converted to lowercase. toLowerCase () is an ES1 feature (JavaScript 1997).

How to convert string to lowercase in angular component templates?

Angular lowercase Pipe used to convert string or text to lowercase in Angular component templates. To convert a string to small letters in template HTML file, pass the input string to the lowercase pipe using pipe operator as shown below. <p> { {'LOWERCASE pipe convert string to small letters in ANGULAR' | lowercase}}</p> <!--

What does the method toLowerCase () return?

The toLowerCase () method returns the value of the string converted to lower case. toLowerCase () does not affect the value of the string str itself. The compatibility table on this page is generated from structured data.

What is toLowerCase ()?

toLowerCase () is an ES1 feature (JavaScript 1997). It is fully supported in all browsers:


2 Answers

This is built into AngularJS and can be access via angular.lowercase(string); and then used in your Controller like:

$scope.makeLowerCase = function(string){
   return angular.lowercase(string);
};

Now use in your DOM like:

{{Car_name|makeLowerCase}}

like image 57
Alpha G33k Avatar answered Sep 29 '22 07:09

Alpha G33k


Option 1

You can do it by using angular.$filter option

Sample look like

<td ng-model={{ lowercase_expression | lowercase}}><td>

$filter('lowercase')()

More details Please see this angular document


Option 2

Please see this below discussion

AngularJS - ngOptions expressions


Option 3

You need to manually add a loop for your array. And convert to the object values to lower case by using toLowerCase() function , and finally push the object to new array.


like image 34
Ramesh Rajendran Avatar answered Sep 29 '22 08:09

Ramesh Rajendran