使用ng-options过滤大写字母

时间:2014-09-30 14:55:48

标签: javascript angularjs ng-options

我在ng-options找不到如何大写或大写第一个字母。

我的选择:

<select ng-model="company.currency.code" ng-options="currency.code as currency.code for currency in currency_list>
</select>

在控制器中:

$scope.currency_list = [
    {
        code: 'eur'
    }, {
        code: 'usd'
    }
];

我想打印&#34; EUR&#34;,&#34; USD&#34;,或&#34; Eur&#34;,&#34; Usd&#34;没有手动循环我的对象。

可以这样做吗?

4 个答案:

答案 0 :(得分:14)

这应该有效:

ng-options="currency.code as (currency.code | uppercase) for currency in currency_list"

请参阅过滤器文档:https://docs.angularjs.org/api/ng/filter/uppercase

答案 1 :(得分:4)

使用 uppercase 过滤器。

看看这个

&#13;
&#13;
var app = angular.module('myApp', []);
app.controller('ArrayController', function ($scope) {
    $scope.currency_list = [
    {
        code: 'eur'
    }, {
        code: 'usd'
    }
];
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app='myApp' ng-controller="ArrayController">
    <select ng-model="company.currency.code" ng-options="currency.code as (currency.code | uppercase) for currency in currency_list | uppercase">
</select>
</div>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

通过将类附加到

,您可以轻松地使用css方法

&#13;
&#13;
var app = angular.module('myApp', []);
app.controller('ArrayController', function ($scope) {
    $scope.currency_list = [
      {
          code: 'eur'
      }, {
          code: 'usd'
      }
    ];
});
&#13;
.text-capitalize{ text-transform: capitalize }
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app='myApp' ng-controller="ArrayController">
    <select 
      class="text-capitalize"
      ng-model="company.currency.code"
      ng-options="currency.code as currency.code for currency in currency_list">
    </select>
</div>
&#13;
&#13;
&#13;

答案 3 :(得分:0)

您可以使用以下属性:
ng-options="currency.code | uppercase for currency in currency_list"