Solution:
Figured it out myself: The whole proble is no problem any longer after applying this fix and doing my custom build of the ui-select. I hope this is going to get into the official master branch some time soon!
Problem
How do I initialize a select with multiple values? I'm trying this but it doesn't show the selected items in the selection.
First I thought it has something do to with the data that I'm getting async via HTTP get but not even the "static" plunker example I've made to show the problem works for me.
I think my issue is that the data comes from two different sources so the index and by this references between the two arrays don't match. The list of categories is fetched with a service and the selected categories come from another service that are returned together with the data set that is attached to them. And in another select it would be pretty impractical to load all 45k users just to pick the selected ones from that huge list.
So how could I make my existing selection data appear in the ui-select?
HTML
<body ng-controller="MainCtrl">
<label>Assigned Categories</label>
<ui-select
multiple
ng-model="categories.selected"
on-select="selectCategory($item, $model)"
on-remove="deselectCategory($item, $model)">
<ui-select-match placeholder="Select Category...">{{$item.name}}</ui-select-match>
<ui-select-choices
repeat="category in categories.categories track by category.id">
{{category.name}}
</ui-select-choices>
</ui-select>
<pre>{{categories | json}}</pre>
</body>
JS
var app = angular.module('plunker', [
'ui.select'
]);
app.controller('MainCtrl', function($scope) {
$scope.categories = {
selected: [
{
"id": "1",
"name": "Foo"
}
],
categories: [
{
"id": "1",
"name": "Foo 1"
},
{
"id": "2",
"name": "Bar 2"
},
{
"id": "3",
"name": "FooBar 3"
}
]
};
});