Angular Error: Property 'map' does not exist on type 'Observable<TimeRecord>'.ts(2339)
Fehlerbeschreibung:
Die Folgefunktion .map kann nicht in angular eingefügt werden. Beispiel .get().map(..)
Property 'map' does not exist on type 'Observable<TimeRecord>'.ts(2339)
Lösung:
In neueren Versionen wird map innerhalb von .pipe(map … ) einefügt. In .pipe können mehrere Folge-Bearbeitungen in serie eingefügt werden.
Error in this code
return this.http .get<TimeRecord>(this.URL) .map((response: TimeRecord) => { return response as TimeRecord; } ) |
Richtig
return this.http .get<TimeRecord>(this.URL) .pipe( map((response: TimeRecord) => { return response as TimeRecord; } ) )
|
Code mit Fehler component.service.ts
Gelöst: Schreibweise in component.service.ts
Solved:
import { Injectable } from '@angular/core'; import { HttpClient } from "@angular/common/http"; // import {Http, Response} from "@angular/http"; import { BehaviorSubject, Observable } from 'rxjs'; //import "rxjs/add/operator/map"; import { map } from 'rxjs/operators'; import { TimeRecord } from '../models/time-records.model';
@Injectable({ providedIn: 'root' }) export class TimerecordsService {
private URL : string="https://localhost:44388/api/TimeRecords";
constructor( private http: HttpClient ) { }
getData():Observable<TimeRecord>{
return this.http .get<TimeRecord>(this.URL) .pipe( map((response: TimeRecord) => { return response as TimeRecord; } ) ) }
}
|
Error:
import { Injectable } from '@angular/core'; import { HttpClient } from "@angular/common/http"; // import {Http, Response} from "@angular/http"; import { BehaviorSubject, Observable } from 'rxjs'; //import "rxjs/add/operator/map"; import { map } from 'rxjs/operators'; import { TimeRecord } from '../models/time-records.model';
@Injectable({ providedIn: 'root' }) export class TimerecordsService {
private URL : string="https://localhost:44388/api/TimeRecords";
constructor( private http: HttpClient ) { }
getData():Observable<TimeRecord>{
return this.http .get<TimeRecord>(this.URL) .map((response: TimeRecord) => { return response as TimeRecord; } ) }
}
|