擷取結果的陣列這是我的服務代碼來獲取結果的數組:無法從angular2服務
getIndustries(): Observable<any> {
return this.http.get(`${IndustriesService.BASE_URI}/?searchTerm=`)
.map((res: Response) => res.json())
.catch((err: any) => Observable.throw('Server Error'));
}
下面是我的部件的構造和與上述定義的服務進行通信的方法。
protected searchData: Array<Industry>;
constructor(private completerService: CompleterService,
private route: ActivatedRoute,
private industriesService: IndustriesService) {
this.fetchIndustryCodes();
}
private fetchIndustryCodes(): Subscription {
return this.route.params
.switchMap((industries: Industry[]) => this.industriesService.getIndustries())
.subscribe((industries_data: Industry[]) => {
this.searchData = industries_data
});
}
當我試圖把它打印出來searchData在構造它打印認購對象。我不知道如何通過上述訂閱獲取數據。
任何方向對此將是一個很大的幫助!
看起來你應該把你的搜索詞作爲url參數發送出去,但你永遠不會填充它「?searchTerm =」...你需要把你的搜索詞變量放在那裏。 – ganders
另外,您是否計劃吞嚥從您的服務呼叫返回的任何錯誤? – ganders