Map doesn't exist on Observable<Object> with angular 6.0.0 and rxjs 6.1.0

前端 未结 7 733
情歌与酒
情歌与酒 2020-12-29 07:46

Hi I\'m trying to follow a tutorial on angular but the tutorial was made in September. I believe the person used angular-cli 1.3.2. I\'m not sure which version of rxjs he wa

7条回答
  •  灰色年华
    2020-12-29 07:55

    In Angular 6x with rxjs 6.3.3 you can do this. In the file(app.component.ts)

    import { Component } from '@angular/core';
    import { HttpClient, HttpParams, HttpHeaders} from '@angular/common/http';
    import { Observable, throwError } from 'rxjs';
    import { map, catchError, retry } from 'rxjs/operators';
    
    @Component({
       selector: 'app-root',
       templateUrl: './app.component.html',
       styleUrls: ['./app.component.css']
    })
    
    export class AppComponent {    
    
      _url = 'http://...';
      constructor( private http: HttpClient ) { }
      articles: Observable;
    
      // Method to get info
      getAPIRest() {       
        const params = new HttpParams().set('parameter', 'value');
        const headers = new HttpHeaders().set('Autorization', 'auth-token');
        this.articles = this.http.get(this._url + '/articles', { params, headers })
                 .pipe( retry(3),
                        map((data => data),
                        catchError(err => throwError(err))));
      }
    

    }

提交回复
热议问题