私はサーバーにオブジェクトのコレクションを持っています。ページが読み込まれたときにng-repeatを設定します。
私はそうのように、サーバー上のリソースからリストをフェッチ作っ工場だった:私は、UI-ルータとでresolveプロパティを使用した場合の前にこのコードの動作を持っていた
app.factory('objectArray', ['$http', function($http) {
// This is returning a $$state object
// instead of response.data...
return $http.post('/get_collection').then(function(response) {
console.log(response.data);
return response.data;
});
}]);
を州の宣言しかし、私のコントローラに直接このファクトリを注入すると、response.dataを取得する代わりに$$状態オブジェクトが取得されます。
私のコントローラは、次のようになります。
app.controller('applicationController', ['$scope', 'objectArray', function($scope, objectArray) {
$scope.array = objectArray;
console.log($scope.array);
}]);
可能な複製?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call); ([this duplicate](http://stackoverflow.com/questions/22951208/return-value-after-a-promise)も参照してください) – Kenney
@Kenney私は、これが何の問題もなく角度ui-routerで動作するのが最も興味があります追加コードですが、この場合は{$$ state:object} –
ですが、わかりませんが、[Promise.then']から値を返すことはできません(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)。あなたのアプローチは[this](https://github.com/angular-ui/ui-router/issues/77)のようなものでしたか? – Kenney