私は2つのWebサービスを持っています:
次のように「Articles」を返します。
[
{
"id": "1",
"headline": "some text",
"body": "some text",
"authorId": "2"
},
{
"id": "2",
"headline": "some text",
"body": "some text",
"authorId": "1"
}
]
そしてもう1つは、IDを指定すると、次のような「作成者」を返します。
{
"id": "1",
"name": "Test Name",
"email": "test@test.com",
"photo": "path/to/img"
}
この2つを組み合わせて、著者名と写真を記事概要リストに表示できるようにします。
このような:
[
{
"id": "1",
"headline": "some text",
"body": "some text",
"authorId": "2",
"author_info": {
"id": "2",
"name": "Another Test Name",
"email": "test2@test.com",
"photo": "path/to/img"
}
},
{
"id": "2",
"headline": "some text",
"body": "some text",
"authorId": "1"
"author_info": {
"id": "1",
"name": "Test Name",
"email": "test@test.com",
"photo": "path/to/img"
}
}
]
記事をフェッチする「Articles」サービスがありますが、「Articles」サービスの出力を返す前に、同様の「Authors」サービスからの著者情報で返されたJSONを強化するための最良のアプローチは何ですか?
factory('Authors', ['$http', function($http){
var Authors = {
data: {},
get: function(id){
return $http.get('/api/authors/' + id + '.json')
.success(function(data) {
Authors.data = data;
})
.error(function() {
return {};
});
}
};
return Authors;
}]).
factory('Articles', ['$http', 'Authors', function($http, Authors){
var Articles = {
data: {},
query: function(){
return $http.get('/api/articles.json')
.success(function(result) {
Articles.data = result; // How to get the author info into this JSON object???
})
.error(function() {
Articles.data = [];
});
}
};
return Articles;
}])
これが完全に間違ったアプローチであるかどうかも教えてください。:)