Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter uppercase with ng-options

I didn't find how to uppercase or uppercase first letter in ng-options.

My select:

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

In controller:

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

I'd like to print "EUR", "USD", or "Eur", "Usd" without looping manually my object.

Is that possible to do this?

like image 271
Syl Avatar asked Sep 30 '14 14:09

Syl


People also ask

Which filter is used to change uppercase letters?

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

How would you take a property called name and convert it to uppercase in angular?

uppercase() Function in AngularJS is used to convert the string into uppercase.

Which of the following is true about uppercase filter?

Q 4 - Which of the following is true about uppercase filter? A - Uppercase filter is a function which takes text as input.

Which of the following filter is used to convert input to all uppercase?

The uppercase filter converts a string to uppercase letters.


2 Answers

This should work:

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

See the filter docs: https://docs.angularjs.org/api/ng/filter/uppercase

like image 112
Stephen Friedrich Avatar answered Oct 30 '22 10:10

Stephen Friedrich


Use uppercase filter.

Take a look at this

var app = angular.module('myApp', []);
app.controller('ArrayController', function ($scope) {
    $scope.currency_list = [
    {
        code: 'eur'
    }, {
        code: 'usd'
    }
];
});
<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>
like image 21
Nidhish Krishnan Avatar answered Oct 30 '22 09:10

Nidhish Krishnan