您可以在控制器负载本身上设置它
标记
<body ng-controller="DemoCtrl">
<p>Selected: {{item.selected}}</p>
<ui-select ng-model="item.selected" theme="select2" ng-disabled="disabled" style="min-width: 300px;">
<ui-select-match placeholder="Select a item in the list">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="item in items | propsFilter: {name: $select.search, age: $select.search}">
<div ng-bind-html="item.Code | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
</body>
代码
app.controller('DemoCtrl', function($scope, $http) {
$scope.disabled = undefined;
$scope.clear = function() {
$scope.item.selected = undefined;
};
$scope.item = {};
$scope.items = [
{ name: 'Item1', Code: 'Code1', },
{ name: 'Item2', Code: 'Code3'},
{ name: 'Item3', Code: 'Code4'},
{ name: 'Item4', Code: 'Code4' },
{ name: 'Item5', Code: 'Code5' },
];
$scope.item.selected = $scope.items[0] //here you can set the item selected
});
工作Plunkr