angular ui select2,绑定数据undefined

时间:2017-07-08 09:22:32

标签: javascript angularjs select ui-select angular-ui-select

我使用angular-ui-select2。

            <select ui-select2 ng-model="vm.salonStaffModel.type">
                <option ng-repeat="occ in vm.categoriesType" value="{{occ.key}}">
                    {{occ.key}}</option>
            </select>

当我从下拉列表中选择值时,我成功地将数据绑定到vm.salonStaffModel.type。但是当我刷新页面时,值是未定义的,尽管vm.salonStaffModel.type具有我之前选择的值。谢谢!

enter image description here

这是我的控制器

export default class SalonStaffCreateCtrl {
  constructor($state, SalonStaff, SalonListService, popUpMessageService) {
    this.submitted = false;
    this.popUpMessageService = popUpMessageService;
    this.salonListService = SalonListService;
    this.salonStaffModel = {
      type:"AUS"
    };
    this.SalonStaff = SalonStaff;
    this.state = $state;
    this.yesNoLazylist = [{ "key": false, "group": null }, { "key": true, "group": null }];
    this.categoriesType = [{"key":"AUS","group":null,"$$hashKey":"object:259"},{"key":"BD","group":null,"$$hashKey":"object:260"},{"key":"735","group":null,"$$hashKey":"object:261"},{"key":"713","group":null,"$$hashKey":"object:262"},{"key":"714","group":null,"$$hashKey":"object:263"},{"key":"IND","group":null,"$$hashKey":"object:264"},{"key":"734","group":null,"$$hashKey":"object:265"},{"key":"711","group":null,"$$hashKey":"object:266"},{"key":"716","group":null,"$$hashKey":"object:267"},{"key":"731","group":null,"$$hashKey":"object:268"},{"key":"BUR","group":null,"$$hashKey":"object:269"},{"key":"NZ","group":null,"$$hashKey":"object:270"},{"key":"PK","group":null,"$$hashKey":"object:271"},{"key":"733","group":null,"$$hashKey":"object:272"},{"key":"SGP","group":null,"$$hashKey":"object:273"},{"key":"717","group":null,"$$hashKey":"object:274"},{"key":"T","group":null,"$$hashKey":"object:275"},{"key":"USA","group":null,"$$hashKey":"object:276"},{"key":"725","group":null,"$$hashKey":"object:277"}];
    this.categoriesService = [];
    this.getServiceSalon();
  }

}

SalonStaffCreateCtrl.$inject = ['$state', 'SalonStaff', 'SalonListService', 'popUpMessageService'];
<div class="form-group">
            <label>Type *</label>
                            <select ui-select2 ng-model="vm.salonStaffModel.type">
                    <option ng-repeat="occ in vm.categoriesType" value="{{occ.key}}">
                        {{occ.key}}</option>
                </select>
            
            <p ng-show="frm.type.$error.required && vm.submitted" class="red-text error-label-dropdown">Mandatory field(s)</p>
          </div>

0 个答案:

没有答案