ng-model在ui-select中未更改 [英] ng-model is not getting changed in ui-select
问题描述
我正在尝试实现一些非常简单的东西:
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>
更改对象时,更改不会反映在模型company.stack中.我尝试将其更改为$ parent.company.stack,但仍然无法正常工作.我想念什么? 我正在使用AngularJS v1.3.0-beta.17.
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.
推荐答案
我在angular 1.3.14
和ui-select
以及将选择项ui-select
指令绑定到数组上遇到了类似的问题.我无法将所选项目绑定到ng-model
中引用的数组.
我通过将selectedItems
包装到一个对象中来使其工作:
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>
直接在$scope
上放置selectedItems
对我不起作用.
Putting selectedItems
directly on the $scope
didn't work for me.
这篇关于ng-model在ui-select中未更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!