撷取结果的阵列这是我的服务代码来获取结果的数组:无法从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