Advertisement
andreadc

example

Feb 29th, 2020
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //codice che non funziona
  2. this.carsService.getCars().pipe(
  3.     filter(car => car.userId == this.userId)) // Property 'userId' does not exist on type 'Car[]
  4.     .subscribe( cars => {
  5.         console.table(cars);
  6.     })
  7.  
  8. //soluzione
  9. this.carService.getCars().pipe(
  10.     map(cars => cars.filter(car => car.userId == this.userId))
  11.     .subscribe( cars => {
  12.         console.table(cars);
  13.     })
  14.  
  15. //carsService.ts
  16.  getCars(){
  17.     let options = {headers:this.headers}
  18.     return this.http.get<Car[]>(this.host + 'getCars', options);
  19.   }
  20.  
  21. // Car model
  22. export class Car {
  23.     username:string;
  24.     id:number;
  25.     model:string;
  26.     brand:string;
  27.     userId:number;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement