問題的默認值:如何設置角度UI選
如何默認值設置爲角度UI選
下拉值是從對象中取出和對象不會被具有默認值。
和ui-select應該在前端設置默認值。
例如:
下拉值如下
1 - 所有水果 2 - 蘋果 3 -banana 4 - 水瓜
值從2至4個是從服務器發送的對象派生的,但前端需要設置默認值,即1 - 所有水果
參考以下通過ui-select2設置的示例如何在ui-select中遷移它?
<select ng-model="fID" class="select" ui-select2 data-placeholder="select fruit">
<option value="">All fruits</option>
<option ng-repeat="f in frits value="{{f.fID}}">{{f.name}}</option>
</select>
<ui-select theme="select2" ng-model="fruits.selected">
<ui-select-match placeholder="select please" allow-clear="false"> {{$select.selected.name}}
</ui-select-match>
<ui-select-choices repeat="f in fruits | filter:$select.search">
<div ng-bind-html="f.name | highlight: $select.search:'underline'"></div>
</ui-select-choices>
</ui-select>
http://plnkr.co/edit/a3KlK8dKH3wwiiksDSn2?p=preview https://github.com/angular-ui/ui-select 鏈接:角UI/UI選
您可以在您的控制器中設置默認值/初始值 – harishr
ng-init會設置一個默認值:https://docs.angularjs.org/api/ng/directive/ngInit – chapman84