Javascript 小写字符串 Angular

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31383047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 06:37:51  来源:igfitidea点击:

tolowercase string Angular

javascriptangularjs

提问by Ptheitroado

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.

我正在尝试将 'Car_name' 更改为 'car_name' 但是服务器填充了 ng-model & Categories[] 条目,所以我不确定如何在我的控制器中观看和转换为小写。

If I could do

如果我能做到

{{Car_name|lowercase}} 

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

将是最简单的,但不确定格式。

回答by Alpha G33k

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

它内置于 AngularJS 中,可以通过访问angular.lowercase(string);,然后在您的控制器中使用,例如:

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

Now use in your DOM like:

现在在你的 DOM 中使用,如:

{{Car_name|makeLowerCase}}

{{Car_name|makeLowerCase}}

回答by Ramesh Rajendran

Option 1

选项1

You can do it by using angular.$filteroption

您可以使用angular.$filter选项来做到这一点

Sample look like

样品看起来像

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

$filter('lowercase')()

More details Please see this angular document

更多细节请看这个角度文件



Option 2

选项 2

Please see this below discussion

请看下面的讨论

AngularJS - ngOptions expressions

AngularJS - ngOptions 表达式



Option 3

选项 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.

您需要手动为您的array. 并使用toLowerCase()function将对象值转换为小写,最后将对象推送到新数组。