简体   繁体   English

使用angular js不会填充下拉列表值

[英]Dropdown values are not getting populated using angular js

I have a user object which I want to edit, On click of edit button few values of form are getting loaded but three values are not getting populated. 我有一个要编辑的用户对象,单击“编辑”按钮时,加载了几个表单值,但没有填充三个值。 I checked from service I am getting the data but it is not populating. 我从服务中检查了我是否正在获取数据,但没有填充数据。

HTML HTML

    <div class="col-xs-4 col-sm-4 col-md-3 col-lg-3 label-right">
        <label class="control-label">{{::'label.country'|translate}}</label>
        <label class="asterisk">*</label>
    </div>
    <div class="col-xs-8 col-sm-8 col-md-9 col-lg-9 controls">
        <select id="selectCountry" name="selectCountry" required ui-select2="select2CountrySettings" ng-model="selectedUser.country">
            <option ng-repeat="country in countryList" value="{{country.name}}" ng-selected="{{country.name == selectedUser.country}}">{{country.name}}</option>
        </select>
        <span class="help-block" ng-show="editUserForm.selectCountry.$dirty && editUserForm.selectCountry.$error.required">{{::'error.required'|translate}}</span>
    </div>
</div>

<!-- Locale -->
<div class="row control-group" ng-class="{error:editUserForm.selectLocale.$dirty && !editUserForm.selectLocale.$valid, success:editUserForm.selectLocale.$valid}">

    <div class="col-xs-4 col-sm-4 col-md-3 col-lg-3 label-right">
        <label class="control-label">{{::'label.user.locale'|translate}}</label>
        <label class="asterisk">*</label>
    </div>
    <div class="col-xs-7 col-sm-7 col-md-9 col-lg-9 controls">
        <select id="selectLocale" name="selectLocale" required class="locale-select" ui-select2="select2LocaleSettings" ng-model="selectedUser.culture">
            <option ng-repeat="locale in localeList" value="{{locale.name}}" ng-selected="{{locale.name == selectedUser.culture}}">{{locale.name}}</option>
        </select>
        <span class="help-block" ng-show="editUserForm.selectLocale.$dirty && editUserForm.selectLocale.$error.required">{{::'error.required'|translate}}</span>
    </div>
</div>

Javascript 使用Javascript

function reloadUser() {
    loadingDataBegin();

    userDetails.getUserById(userDetails.getSelectedUser().id).then(function (response) {
        $scope.selectedUser = response.results;
    }, function (error) {
        if (error.status !== undefined && (error.status === 401 || error.status === 403)) {
            $rootScope.authentication.reAuthenticate();
        } else {
            toasty.generalError();
        }
    });
}

In $scope.selectedUser I am getting all the values from service Last three dropdowns Locale, Country and Organization is not getting populated (image) in dropdown. $scope.selectedUser我从服务的最后三个下拉列表中获取所有值下拉列表中未填充区域设置,国家和组织(图像)

  1. Use ng-options it will make your selected item in the select boxes 使用ng-options将使您选择的项目在选择框中

How to use it 如何使用它

ng-options="item.id as item.name for item in names"
  1. use ng-if to assign the value to the corresponding model 使用ng-if将值分配给相应的模型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM