ng-model is not getting changed in ui-select

TeknasVaruas picture TeknasVaruas · Sep 19, 2014 · Viewed 13.1k times · Source

I'm trying to achieve something very straightforward:

<ui-select multiple ng-model="company.stack" theme="bootstrap">
    <ui-select-match>{$$item.name$}</ui-select-match>
    <ui-select-choices repeat="technology in technologies | filter: $select.search">
        <div ng-bind-html="technology.name | highlight: $select.search"></div>
    </ui-select-choices>
</ui-select>

When changing the objects, the changes are not reflected in the model company.stack. I tried changing it to $parent.company.stack, but it still doesn't work. What am I missing? I'm using AngularJS v1.3.0-beta.17.

Answer

AunAun picture AunAun · Apr 28, 2015

I had a similar issue with angular 1.3.14 and ui-select and a multiple-choice ui-select directive binding to an array. I was not able to bind the selected items to an array referred to in ng-model. I got it to work by wrapping selectedItems into an object:

$scope.myObj = { selectedItems : []};
...

<ui-select ng-model="myObj.selectedItems" ...>
</ui-select>

Putting selectedItems directly on the $scope didn't work for me.