Readdy Write

solved: Angular Error: Property 'map' does not exist on type 'Observable '.ts(2339)

25.01.2021 (👁5403)

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((responseTimeRecord=> {

           return response as TimeRecord;

         }

    )

 

 

 

Richtig

    return this.http

    .get<TimeRecord>(this.URL)

    .pipe(

      map((responseTimeRecord=> {

           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 { BehaviorSubjectObservable } 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";

  constructorprivate httpHttpClient  ) { }

  getData():Observable<TimeRecord>{

    

    return this.http

    .get<TimeRecord>(this.URL)

    .pipe(

      map((responseTimeRecord=> {

           return response as TimeRecord;

         }

        )

    )

  }

}



 

 

 

 

Error:

import { Injectable } from '@angular/core';

import { HttpClient } from "@angular/common/http";

// import {Http, Response} from "@angular/http";

import { BehaviorSubjectObservable } 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";

  constructorprivate httpHttpClient  ) { }

  getData():Observable<TimeRecord>{

    

    return this.http

    .get<TimeRecord>(this.URL)

      .map((responseTimeRecord=> {

           return response as TimeRecord;

         }

    )

  }

}

    


0,00 €