Search code examples
javascriptangularjsangular-ui-select

Value of Angular ui-select


In my application have 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>

After chosing something i want to add value of select to database.

Before i'm using input and dont have a problem with adding to database.

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

This is part of my controller:

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' }
    ];

Solution

  • Here is the fix to this issue:

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

    and

     <div ng-bind-html="t.type | highlight: $select.search"></div>