简体   繁体   English

Angular 4 HttpClientModule

[英]Angular 4 HttpClientModule

How does this code change wrt to the new HttpClientModule, where mapping from response.json() is not required. 如何将此代码更改为新的HttpClientModule,其中不需要来自response.json()的映射。

    //uses Http
    getLegalTerms(): Observable<legalterm[]> {
        return this._http.get(this._legalTermUrl)
        .map((response: Response) => <legalterm[]> response.json());
    }

i get nothing back if I do the following 如果我做以下事情,我什么也得不到

    //uses HttpClientModule
    getLegalTerms(): Observable<legalterm[]> {
        return this._http.get<legalterm[]>(this._legalTermUrl)
    }

I am subscribing in the component class in the same way in either case 在任何一种情况下,我都以相同的方式订阅组件类

     ngOnInit() {
        this._legalTermService.getLegalTerms()
         .subscribe((legalTerms: LegalTerm[])  =>  {
         this.legalTerms = legalTerms;
      })
    }

I get data in the grid with Http but no data in grid with HttpClient 我使用Http在网格中获取数据,但是使用HttpClient在网格中没有数据

Thank you! 谢谢! Anand 阿南德

It should be, 它应该是,

 getLegalTerms(): Observable<legalterm[]> {
        return this._http.get(this._legalTermUrl)
        //.map((response: Response) => <legalterm[]> response);
       .map((response: Response) => <any> response);
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM