AngularJS ui-select 下拉默认值
AngularJS ui-select dropdown default value
我正在使用 angular ui-select 作为下拉菜单。如何为下拉值设置默认值?
<h3>Selectize theme</h3>
<p>Selected: {{country.selected}}</p>
<ui-select ng-model="country.selected" theme="selectize" ng-disabled="disabled" style="width: 300px;">
<ui-select-match placeholder="Select or search a country in the list...">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="country in countries | filter: $select.search">
<span ng-bind-html="country.name | highlight: $select.search"></span>
<small ng-bind-html="country.code | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>
该片段来自 plnkr.co。目前下拉列表只是播种默认 Select or search a country in the list...
但我需要从控制器传递一个值。让我们说 $scope.default = {"name":"Decard"}
谢谢!!
编辑
此题与类似,但涉及json return数据格式。
您可以将 ng-model 初始化为控制器中的默认国家/地区对象,如下所示:
$scope.country = {};
$scope.country.selected = {name: 'Albania', code: 'AL'};
然后使用"ui-select-match"设置默认值如下:
<ui-select ng-model="country.selected" theme="selectize" ng-disabled="disabled" style="width: 300px;">
<ui-select-match placeholder="Select or search a country in the list...">{{ $select.selected.name }}</ui-select-match>
<ui-select-choices repeat="country in countries | filter: $select.search">
<span ng-bind-html="country.name | highlight: $select.search"></span>
<small ng-bind-html="country.code | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>
我正在使用 angular ui-select 作为下拉菜单。如何为下拉值设置默认值?
<h3>Selectize theme</h3>
<p>Selected: {{country.selected}}</p>
<ui-select ng-model="country.selected" theme="selectize" ng-disabled="disabled" style="width: 300px;">
<ui-select-match placeholder="Select or search a country in the list...">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="country in countries | filter: $select.search">
<span ng-bind-html="country.name | highlight: $select.search"></span>
<small ng-bind-html="country.code | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>
该片段来自 plnkr.co。目前下拉列表只是播种默认 Select or search a country in the list...
但我需要从控制器传递一个值。让我们说 $scope.default = {"name":"Decard"}
谢谢!!
编辑
此题与
您可以将 ng-model 初始化为控制器中的默认国家/地区对象,如下所示:
$scope.country = {};
$scope.country.selected = {name: 'Albania', code: 'AL'};
然后使用"ui-select-match"设置默认值如下:
<ui-select ng-model="country.selected" theme="selectize" ng-disabled="disabled" style="width: 300px;">
<ui-select-match placeholder="Select or search a country in the list...">{{ $select.selected.name }}</ui-select-match>
<ui-select-choices repeat="country in countries | filter: $select.search">
<span ng-bind-html="country.name | highlight: $select.search"></span>
<small ng-bind-html="country.code | highlight: $select.search"></small>
</ui-select-choices>
</ui-select>