Restangular を使用して、アイテムをコレクションに追加した後、バックエンド サービスから取得した要素の外部キー フィールドを展開しようとしています。
url
サービスは、関連するオブジェクトにリンクするフィールドを含む要素で POST に応答します。これらのオブジェクト用のサービスは既に用意されています。
応答は次のようになります。
{
"url": "http://api.example.com/resources/6/",
"name": "Harry",
"role": "http://api.example.com/roles/1/",
}
role
フィールドを次のように拡張したいと思います。
{
"url": "http://api.example.com/resources/6/",
"name": "Harry",
"role": "Administrator",
}
これまでのところ、私は次のものを持っています:
Configurer.setResponseInterceptor(function(data, operation, what, url, response, deferred) {
if ((operation == 'post' || operation == 'put') && what == 'resources' && 'role' in data && data.role.substr(0,4) == 'http') {
console.log('Role URL instead of name -- change this');
}
return data;
});
理想的には、Restangular をラップする既存のサービスを呼び出したいと思います。インジェクターは必要ですか?それとももっと良い方法がありますか?