Value of Angular ui-select



在我的应用程序中有ui-select:

<ui-select ng-model="flat.flatData.type_local" theme="bootstrap">
   <ui-select-match placeholder="Type">
      {{ $select.selected.type }}
   </ui-select-match>
   <ui-select-choices repeat="t in flat.type_local | filter: $select.search">
      {{ t.type }}
   </ui-select-choices>
</ui-select>

选择后,我想添加的值选择数据库。

在我使用输入之前,没有添加到数据库的问题。

<input type="text" class="form-control input-sm" name="type" ng-model="flat.flatData.type_local" placeholder="Type" required>

这是我的控制器的一部分:

angular.module('flatCtrl', ['flatService', 'ui.grid', 'ui.grid.resizeColumns', 'ui.grid.moveColumns', 'ui.grid.autoResize', 'ngSanitize', 'ui.select'])
.controller('FlatController', function(Flat, socketio){
    vm = this;
    vm.createFlat = function(){
        vm.message = '';
        Flat.create(vm.flatData)
            .success(function(data){
                // clear up the form
                vm.flatData = '';
                vm.message = data.message;
            });
    };

    vm.type_local = [
        { type: 'One' },
        { type: 'Two' }
    ];

修复方法如下:

 <ui-select-choices repeat="t.type as t in flat.type_local track by $index | filter: $select.search">

 <div ng-bind-html="t.type | highlight: $select.search"></div> 
<input type="text" class="form-control input-sm" name="type" 
       ng-model="flat.type_local" placeholder="Type" required>

最新更新