ItSolutionStuff.com

Angular - Cannot find name 'HttpParams' - Solved

By Hardik Savani • May 2, 2024
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: Angular
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Angular Get Current Used Port Number Example

Read Now →

Angular HttpHeaders Example Tutorial

Read Now →

Angular 13 HttpClient & Http Services Tutorial Example

Read Now →

Image Upload in Angular 12 Tutorial

Read Now →

Angular Upgrade from 11 to 12 Version Example

Read Now →

Angular Material Mat Table Vertical Scroll Example

Read Now →

How to use Owl Carousel In Angular 11?

Read Now →

Angular 11 Radar Chart using ng2-charts Example

Read Now →

Angular Material Datepicker Disable Specific Dates Example

Read Now →

Angular Google Maps Get Current Location

Read Now →

Angular Get Element By Id Value Example

Read Now →