aish
aish

Reputation: 623

How to Capitalize first letter of each word in ng-options?

I have a select box for listing locations. The list includes id and value.

My script goes like this

    <script>
    $scope.fillLocationList = function (item) {
                $http({
                    method: 'POST',
                    url: url,
                    data: {                            
                        'country': item
                    }
                }).then(function (result) {
                    $scope.LocatorList = result.data;                                                        
                });
            };
    $scope.fillLocationList($scope.formData.country);
    </script>
<select name="location" id="location" class="selectcontact" ng-model="formData.locations" ng-options="item.key_value for item in LocatorList track by item.key_id"></select>

I need to display place name as "Dubai Internet City".

How can I make the list capitalize for each word in angularjs?

Upvotes: 0

Views: 4482

Answers (2)

aish
aish

Reputation: 623

included custom filter

$scope.filter('capitalize', function() {
        return function(input) {
            return (!!input) ? input.split(' ').map(function(wrd){return wrd.charAt(0).toUpperCase() + wrd.substr(1).toLowerCase();}).join(' ') : '';
        }
    });

ng-options="item.key_value as (item.key_value | capitalize) for item in LocatorList track by item.key_id"

Upvotes: 1

Sajeetharan
Sajeetharan

Reputation: 222582

You can use the filter uppercase

ng-options="item.key_value as (item.key_value | uppercase) for item in LocatorList track by item.key_id"

Upvotes: 2

Related Questions