我试图在每次单击按钮时添加一个新的选择,
html:
<div ng-repeat = "select in selects track by $index">
<ui-select ng-model="selects[$index]" theme="select2" ng-disabled="disabled" style="min-width: 300px;">
<ui-select-match placeholder="Select a person in the list or search his name/age...">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="person in people">
<div ng-bind-html="person.name | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
</div>
<button ng-click="addNewSelect()"> Add new select</button>
控制器:
$scope.selects = [{}];
$scope.addNewSelect = function() {
$scope.selects.push({});
}
对象数组保存在数组“selects”中,但占位符不会出现在 selects 中,因为我最初使用空对象初始化 ng-model。在这种情况下如何让占位符起作用?
这里是Plunker对于相同的。
你错过了.selected
之后selects[$index]
.
如果没有这个, ui-select 会认为您选择了一个空对象(selects[$index]
) 并且不会显示占位符。
<ui-select ng-model="selects[$index].selected" theme="select2" ng-disabled="disabled" style="min-width: 300px;">
http://plnkr.co/edit/56SHyE01BJ4EXglLlIcb?p=preview
您也不需要使用索引查找,您可以只使用select.selected
<ui-select ng-model="select.selected" theme="select2" ng-disabled="disabled" style="min-width: 300px;">
http://plnkr.co/edit/3Uq8lDtDOaj5mIZVrCfv?p=preview
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)