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>
将 selectedItems
直接放在 $scope
上对我不起作用.
Putting selectedItems
directly on the $scope
didn't work for me.
这篇关于ng-model 在 ui-select 中没有改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!