Angularjs 如何在ng选项中大写每个单词的第一个字母?

Angularjs 如何在ng选项中大写每个单词的第一个字母?,angularjs,Angularjs,我有一个用于列出位置的选择框。该列表包括id和值 我的剧本是这样的 <script> $scope.fillLocationList = function (item) { $http({ method: 'POST', url: url, data: {

我有一个用于列出位置的选择框。该列表包括id和值

我的剧本是这样的

    <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>

$scope.fillLocationList=函数(项){
$http({
方法:“POST”,
url:url,
数据:{
“国家”:项目
}
}).然后(函数(结果){
$scope.LocatorList=result.data;
});
};
$scope.fillLocationList($scope.formData.country);
我需要将地名显示为“迪拜互联网城”


如何使angularjs中每个单词的列表大写?

您可以使用过滤器

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

您可以使用过滤器

ng-options="item.key_value as (item.key_value | uppercase) for item in LocatorList track by item.key_id"
包括自定义过滤器

$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"
包括自定义过滤器

$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"

Inside.then()函数执行循环并使用函数使单词大写。请参阅问题Inside.then()函数执行循环并使用函数使单词大写。请参阅问题谢谢您的回答,我只需要大写第一个字母,而不是整个单词。我为大写定制了自定义筛选器。为什么要删除筛选器?您的筛选器是为了大写整个单词。为什么有问题谢谢您的答复,我只需要大写第一个字母,而不是整个单词。我为大写定制了自定义筛选器。为什么要移除筛选器?您的筛选器是为了大写整个单词。为什么会出现问题