提问者:小点点

Angular订阅HTTPClient Observable,错误req.url。toLowerCase不是函数


我正在使用一个服务从url中检索数据,我正在另一个组件中使用该服务在前端中显示数据。。。

我的服务:

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错误类型Error: req.url.toLowerCase不是HttpXsrfInterceptor.push中的函数../node _ modules/@ angular/common/Fe sm5/http . js . httpxsrfinterceptor . intercept(http . js:2027)../node _ modules/@ angular/common/Fe sm5/http . js . httpinterceptorhandler . handle(http . js:1407)位于HttpInterceptingHandler.push..MergeMapSubscriber.push上的/node _ modules/@ angular/common/Fe sm5/http . js . httpinterceptinghandler . handle(http . js:2080)../node _ modules/rxjs/_ es M5/internal/operators/merge map . js . merge map subscriber . _ try next(merge map . js:117)../node _ modules/rxjs/_ es M5/internal/operators/merge map . js . merge map subscriber . _ next(merge map . js:107)../node _ modules/rxjs/_ es M5/internal/subscriber . js . subscriber . next(subscriber . js:93)at Observable。_ subscribe(scalar . js:5)at observable . push../node _ modules/rxjs/_ es M5/internal/observable . js . observable . _ try subscribe(observable . js:176)at observable . push../node _ modules/rxjs/_ es M5/internal/observable . js . observable . subscribe(observable . js:161)

我该如何做才能不出错地检索数据呢?


共1个答案

匿名用户

请试试这个,让我知道

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;}
        )
      }