Javascript ng模型初始化时角度ui选择占位符不工作
我试图在每次单击按钮时添加一个新的选择 html:Javascript ng模型初始化时角度ui选择占位符不工作,javascript,angularjs,select,angularjs-select2,ui-select,Javascript,Angularjs,Select,Angularjs Select2,Ui Select,我试图在每次单击按钮时添加一个新的选择 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 perso
<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>
对象数组保存在数组“selects”中,但占位符不会出现在selects中,因为我最初使用空对象初始化ng模型。在这种情况下,如何使占位符工作
以下是相同的示例。在
选择[$index]
之后,您将缺少所选的
如果没有此选项,ui select会认为您选择了一个空对象(选择[$index]
),并且不会显示占位符
<ui-select ng-model="selects[$index].selected" theme="select2" ng-disabled="disabled" style="min-width: 300px;">
添加css显示的最快方法:块占位符项
.select2-chosen{
display: block !important;
}
在某些情况下,上述解决方案效果很好,但实际情况并非如此
<ui-select ng-model="selectedChannel"
on-select="$ctrl.channelSelected(selectedChannel)">
<ui-select-match placeholder="Select Channel Type">
{{selectedChannel.text}}
</ui-select-match>
<ui-select-choices ui-select-header-group-selectable="$ctrl.selectGroupHeader"
group-by="groupFindChannel"
repeat="channel in (r.channels | filter: $select.search) track by channel.id">
<div ng-bind-html="channel.text | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
希望能有所帮助…之前使用的是angularstrap选择,即使对象为空,也会出现最初的占位符,所以错过了这个,谢谢
.select2-chosen{
display: block !important;
}
<ui-select ng-model="selectedChannel"
on-select="$ctrl.channelSelected(selectedChannel)">
<ui-select-match placeholder="Select Channel Type">
{{selectedChannel.text}}
</ui-select-match>
<ui-select-choices ui-select-header-group-selectable="$ctrl.selectGroupHeader"
group-by="groupFindChannel"
repeat="channel in (r.channels | filter: $select.search) track by channel.id">
<div ng-bind-html="channel.text | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
$scope.selectedChannel = null;