Angular Cannot find name ‘HttpParams’

Angular Cannot find name ‘HttpParams’

Error cannot find name HttpParams in angular; Through this tutorial, we will find a solution for error cannot find HttpParams in angular applications.

And we can also use this solution with angular versions like angular 8, angular 9, angular 10, angular 11, angular 12, angular 13,angular 14, 15 and 16 to resolve error cannot find HttpParams module.

Angular Cannot find name ‘HttpParams’

Now, we can see the solution to error cannot find the name HttpParams in angular; is as follow:

First of all, import HttpParams from @angular/common/HTTP from npm package; is as follows:

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

Let’s see the example of how to import HttpParams from @angular/common/HTTP from npm package; is as follows:

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);
        });
  }
}

Conclusion

Through this tutorial, we have found a solution for the ‘error cannot find HttpParams in angular applications’ and fixed this error as well.

Recommended Tutorials

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *