In an angular application, I used ordinary input earlier:

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

There is a need to use select instead of some input. For this, I installed angular ui-select and now instead of the above input I have ui-select:

 <ui-select ng-model="flat.flatData.type_local" on-select="someFunction(item, model)" 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"> <div ng-bind-html="t.type | highlight: $select.search"></div> </ui-select-choices> </ui-select> 

My controller looks like this:

 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.type_local = {}; 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' } ]; vm.counter = 0; vm.someFunction = function (item, model){ vm.counter++; vm.eventResult = {item: item, model: model}; }; 

The problem is that in the case of inputs everything works, and their value is successfully written to the MongoDB database. In the case of a select, its value is not recorded in the database, although the values ​​of the remaining inputs are still successfully recorded.

    1 answer 1

    It is convenient and necessary to use ngOptions for such purposes.

     <select name="type" ng-model="type" ng-options="type.id as type.name for type in types"> <option value="">Выберите</option> </select> 

    type.name is the name of the select, type.id is the value of the select, that is, what should be saved to the database.

    You can also manually assign a value, as you are doing now. For example:

     ng-change="valueForSaveToDB = type.id" 
    • Yes, I know about it, but I wanted to use exactly ui-select, since there are many built-in additional options that I need in the future. Thanks for the reply, also very helpful! - Eugeniusz Zuev