正確な用語がわからないため、タイトルが正確かどうかは不明です。角度2観察可能な[]
次のようなコードがあるとします。
最初のメソッドを使用して個々のリソースを読み込むと、map(...)に渡された関数でプレーンなJSオブジェクトをラップ/デコレートするリッチモデルクラスのインスタンスを作成できます。
レスポンスがCourseオブジェクトの配列である2番目の方法で同じ結果を得るにはどうすればよいですか?
@Injectable()
export class CourseService {
constructor(private restangular: Restangular) {
}
public getCourse(id: number): Observable<any> {
return this.restangular.one("courses", id).get().map(response =>
new Course(response)
);
}
public getAllCourses(): Observable<any> {
return this.restangular.all("courses").getList().map(response => {
//an array of courses
console.log(response);
});
}
}
これは素晴らしいです! –