あなたが示したこと:
HTML
<p>
<input type="text" ng-model="tags"
ui-select2="{tags: [{id:4, text:'red'},{id:2, text:'blue'},{id:8, text:'white'},{id:41, text:'green'},{id:13, text:'yellow'}]}" />
</p>
Angular-UI
angular.module('app').controller('MainCtrl', function($scope) {
$scope.message = "Will load shortly...";
$scope.tags = [8, 2];
$scope.message = 'Loaded';
});
http://plnkr.co/edit/wUQq8P?p=preview
なぜそれが機能したのですか?わからない。おそらく、タイプがあったか、何かが正しくロードされませんでした。私は Angular や Select2 を使用したことがないので、これを機能させるには数回の試行が必要でした。
うーん。さて、あなたのコードをそのまま plunk にコピーします。他に変更はありません。
http://embed.plnkr.co/wUQq8P
したがって、私が理解していない問題か、コードの別の場所にある問題を推測しています。
これは、AJAX と簡単に組み合わせることができる方法を使用して、最初に動作する例でした。
HTML
<body ng-controller="MainCtrl">
<h4>{{message}}</h4>
<p>
<input type="text" ui-select2="options" ng-model="tags" />
</p>
</body>
Angular-UI
angular.module('app').controller('MainCtrl', function($scope) {
$scope.message = "Will load shortly...";
$scope.options = {
tags: [
{id:4, text:'red'},
{id:2, text:'blue'},
{id:8, text:'white'},
{id:41, text:'green'},
{id:13, text:'yellow'}
]
};
$scope.tags = [8, 2];
$scope.message = 'Loaded';
});
http://plnkr.co/edit/wUQq8P?p=preview