昨日Angular JSを使い始めたばかりですが、何か明白なことを尋ねている場合は申し訳ありません。私がやろうとしているのは、選択の最初のオプションをデフォルトで選択されているものにすることですが、フロントエンドで注文されているため、間違ったオプションが選択されています。最初のアイテムを選択する前に、コントローラー内からの API 呼び出しから返されたデータを並べ替える必要があると思いますか?
これが私の選択です:
<select ng-model="clientsList" ng-options="c.Name for c in clients | orderBy:'Name'"></select>
これが私のコントローラーです:
function MyCtrl($scope, $http) {
$scope.init = $http.jsonp('http://MY-API?callback=JSON_CALLBACK')
.then( function ( response ) {
$scope.clients = response.data;
// need to select something, unfortunately, this won't be the first option on the front end because it's re-ordered alphabetically there
$scope.clientsList = $scope.clients[0];
});
}