我正在使用服务从url检索数据,我正在其他组件中使用该服务在Frontend中显示数据...
我的服务:
getHttpData(baseurl, prefix?, suffix?, startTime?, endTime?, demo_id?) {
return this.http.get(baseurl+ prefix + suffix+ startTime + endTime + demo_id).map(
(res: Response) => {return this.data = res;}
)
}
使用该服务的我的组件:
ngOnInit() {
baseurl: 'http://localhost:6666/some/tra/la/la98321';
this.data = this.genHttp.getHttpData(this.baseurl).subscribe(result => {
this.data = result;
console.log('Daten:',this.data);
});
}
但是我在控制台中收到以下错误:
core.js:1633错误TypeError:req.url.toLowerCase不是函数 在HttpXsrfInterceptor.push ../ node_modules/@angular/common/fesm5/http.js.HttpXsrfInterceptor.intercept (http.js:2027) 在HttpInterceptorHandler.push ../ node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http.js:1407) 在HttpInterceptingHandler.push ../ node_modules/@angular/common/fesm5/http.js.HttpInterceptingHandler.handle (http.js:2080) 在MergeMapSubscriber.project(http.js:1158) 在MergeMapSubscriber.push ../ node_modules / rxjs / _esm5 / internal / operators / mergeMap.js.MergeMapSubscriber._tryNext (mergeMap.js:117) 在MergeMapSubscriber.push ../ node_modules / rxjs / _esm5 / internal / operators / mergeMap.js.MergeMapSubscriber._next (mergeMap.js:107) 在MergeMapSubscriber.push ../ node_modules / rxjs / _esm5 / internal / Subscriber.js.Subscriber.next (Subscriber.js:93) 在Observable._subscribe(scalar.js:5) 在Observable.push ../ node_modules / rxjs / _esm5 / internal / Observable.js.Observable._trySubscribe中 (Observable.js:176) 在Observable.push ../ node_modules / rxjs / _esm5 / internal / Observable.js.Observable.subscribe (Observable.js:161)
我将如何做才能无误地检索数据?
答案 0 :(得分:0)
请尝试一下,让我知道
getHttpData(baseurl, prefix?, suffix?, startTime?, endTime?, demo_id?) {
const url= baseurl+ prefix + suffix+ startTime + endTime + demo_id+'';
return this.http.get(url).map(
(res: Response) => {return this.data = res;}
)
}