我在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;没有手动循环我的对象。
可以这样做吗?
答案 0 :(得分:14)
这应该有效:
ng-options="currency.code as (currency.code | uppercase) for currency in currency_list"
答案 1 :(得分:4)
使用 uppercase 过滤器。
看看这个
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;
答案 2 :(得分:0)
通过将类附加到
,您可以轻松地使用css方法
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;
答案 3 :(得分:0)
您可以使用以下属性:
ng-options="currency.code | uppercase for currency in currency_list"