0
我是個有點新的觀測量,我已經成功發送一個POST API請求並獲得一個正確的JSON響應:Angular2觀察到與後 - 訪問響應
{"id":138,"date":"2017-02-23T05:10:18"}
但是我不確定如何訪問此迴應並做一些用它。這是帖子的服務:
// sends a media(file blob) object to WP API
updateMedia(file: File): Observable<File> {
let headers = new Headers({
'Access-Control-Expose-Headers': 'Authorization, Content-Type, Content-Disposition',
'Content-Type': 'multipart/form-data',
'Content-Disposition': 'attachment; filename='+file.name,
'Authorization': 'Basic cmh5c0B0aGVpdHRlYW0uY29tLmF1OkRlc3Ryb3lfMSE='
});
let options = new RequestOptions({ headers: headers }); // Create a request option
return this.http.post(BASE_API, file, options)
.map((response: Response) => response.json());
}
這裏是我的可觀察到:
onUpdateMedia(file: File) {
this.mediaService
.updateMedia(file)
.subscribe((
file: File) => {
this.file = Object.assign({}, this.file, event);
});
console.log(event); //hmm not what i want
}
任何幫助表示讚賞