我使用UI-SELECT元素在Angular中编写了一个小程序。这是HTML代码:
<ui-select ng-model="test.selectedContract">
<ui-select-match >
{{$select.selected.name}} - {{$select.selected.value}} ---- {{$select.selected.id.id}} *** {{$select.selected.policy.info.name }}
</ui-select-match>
<ui-select-choices group-by="groupByLetter"
repeat="contract in (contracts |
orSearchFilter: {id.id: $select.search, policy.info.name : $select.search} |
orderBy: 'name') track by contract.name">
{{contract.name}} - {{contract.value}} ---- {{contract.id.id}} *** {{contract.policy.info.name }}
</ui-select-choices>
</ui-select>
这是我的合同对象的结构:
$scope.contracts = [{
name: "contract1.00",
value: 10,
id: {
id: 8000,
code: 2
},
policy: {
info: {
name: "test1",
country: "test"
}
}
}, //other contract objects
最后,有我的plunker代码:http://plnkr.co/edit/pigjgcj5ukxscscjc7wl97?p = preview
问题是我要显示" all" 作为默认值(如果没有选择),而我的plunker中的默认值则为:"
您能帮我设置此默认值吗?谢谢!
您可以在控制器中定义某种tostring函数,并将其结果放在UI选择的标签中,而不是硬代码破折号和星星。如果值为null,则应返回" all"
只是设置
$scope.test.selectedContract = {
name: "all",
value: 10,
id: {
id: 8000,
code: 2
},
policy: {
info: {
name: "test1",
country: "test"
}
}
}
demo