import {BehaviorSubject, ReplaySubject} from ‘rxjs’;
private subFileData = new BehaviorSubject(null);
getFileApi(data) {
this.http.post(apiUrl).subscribe(e => {
return this.subFileData.next(e);
});
}
returnFileApi(): Observable {
return this.subFileData.asObservable();
}
假設 api 回傳結果會是:
{
STATUS: “20201023001”,
Result: {
data: …
}
}
在我的Component裡:
test () {
this.api.returnFileApi().subscribe(e => {
this.data = e;
console.log(this.data.Result.data);
});
}
光是取到Result就會報錯了
請問要怎麼取得api裡的資料