Angular 4 HttpClientModule

How does this code change wrt to the new HttpClientModule, where no mapping from response.json () is required.

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

I get nothing if I do the following

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

I subscribe to the component class in the same way anyway

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

I get data in a grid with Http, but no data in a grid with HttpClient

Thank! Anand

+4
source share
1 answer

Must be

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

Source: https://habr.com/ru/post/1688895/


All Articles