Angular - Cannot find name 'HttpParams' - Solved
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Angular Get Current Used Port Number Example
- Angular HttpHeaders Example Tutorial
- Angular 13 HttpClient & Http Services Tutorial Example
- Image Upload in Angular 12 Tutorial
- Angular Upgrade from 11 to 12 Version Example
- Angular Material Mat Table Vertical Scroll Example
- How to use Owl Carousel In Angular 11?
- Angular 11 Radar Chart using ng2-charts Example
- Angular Material Datepicker Disable Specific Dates Example
- Angular Google Maps Get Current Location
- Angular Get Element By Id Value Example