Angular - Cannot find name 'HttpParams' - Solved

By Hardik Savani November 5, 2023 Category : Angular

This tutorial will give you example of Cannot find name 'HttpParams' in angular. I explained simply about angular error ts2304 cannot find name 'HttpParams'. you will learn angular cannot find HttpParams error. you can understand a concept of angular cannot find name HttpParams. Let's see bellow example solve cannot find name HttpParams angular error.

You can use this solution with angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, angular 14, angular 15, angular 16 and angular 17 version.

In this post, I will give you the solution of "Cannot find name 'HttpParams'" in angular application. we need to import HttpParams from @angular/common/http library. so let's see below the solution and full code.

Solution:

let's import HttpParams from @angular/common/http npm package, as bellow:

Import HttpParams:

import { HttpParams } from '@angular/common/http';

Let's see bellow working code:

Example:

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

import { HttpClient, HttpParams } from '@angular/common/http';

@Component({

selector: 'app-root',

templateUrl: './app.component.html',

styleUrls: ['./app.component.css']

})

export class AppComponent {

title = 'fullcal';

/*------------------------------------------

--------------------------------------------

Define constructor

--------------------------------------------

--------------------------------------------*/

constructor(private http: HttpClient) {}

/*------------------------------------------

--------------------------------------------

Define ngOnInit()

--------------------------------------------

--------------------------------------------*/

ngOnInit() {

let auth_token = "asasa21212....";

let params = new HttpParams();

params = params.append('_page', 1);

params = params.append('_limit', 10);

const requestOptions = { params: params };

this.http

.get('http://localhost:8001/events.php', requestOptions)

.subscribe((res: any) => {

console.log(res);

});

}

}

I hope it can help you...

Tags :
Shares