Home > Blockchain >  Property 'pipe' doesn't exist on type 'HttpParams' Angular
Property 'pipe' doesn't exist on type 'HttpParams' Angular

Time:12-25

I just started learning Angular. I found a guide in YouTube but while I was copying the code there was an error.

My task

  1. I need to get data from fakestoreapi.com/products that matches my interface IProduct
  2. Elements should be 5
  3. Should be a 2 second delay

My code: `

import { Injectable } from "@angular/core";
import {HttpClient, HttpErrorResponse, HttpParams} from "@angular/common/http";
import {catchError, delay, Observable} from "rxjs";
import {IProduct} from "../models/product";

@Injectable({
    providedIn: 'root'
})
export class ProductsService {
    constructor(private http: HttpClient) {

    }

    getAll(): Observable<IProduct[]> {
        return this.http.get<IProduct[]>("https://fakestoreapi.com/products", {
            params: new HttpParams({
                fromObject: {limit: 5}
            }).pipe( //error 
                delay(2000)
            )
        });
    }
}

`

I didn't find this method in documentation, but it was in guide!

Screenshot of guide: enter image description here

CodePudding user response:

The pipe part is positioned at the wrong place.

return this.http
           .get<IProduct[]>("https://fakestoreapi.com/products", {
              params: new HttpParams({
                fromObject: {limit: 5}
              })
            })
            .pipe( //error 
                delay(2000)
            );

Check the official documentation of Angular Http Client

  • Related