Angular - Cannot find name 'HttpHeaders' - Solved
Here, I will show you how to works Cannot find name 'HttpHeaders' in angular. you'll learn angular error ts2304 cannot find name 'HttpHeaders'. you can understand a concept of angular cannot find HttpHeaders error. In this article, we will implement a angular cannot find name HttpHeaders. Let's get started with solve cannot find name HttpHeaders 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 'HttpHeaders'" in angular application. we need to import HttpHeaders from @angular/common/http library. so let's see below the solution and full code.
Error Preview:
Solution:
let's import HttpHeaders from @angular/common/http npm package, as bellow:
Import HttpHeaders:
import { HttpHeaders } from '@angular/common/http';
Let's see bellow working code:
Example:
import { Component } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'fullcal';
constructor(private http: HttpClient) {}
ngOnInit() {
const headers = new HttpHeaders({
'Content-Type':'application/json; charset=utf-8',
'myCustomHeader':'itsolutionstuff.com'
});
const requestOptions = { headers: headers };
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 13 Material Datepicker Tutorial Example
- Angular 13 Image Upload with Preview Tutorial
- Angular 13 Reactive Forms Validation Tutorial Example
- Angular Get Difference Between Two Dates in Days
- Angular Custom Markdown Pipe Example
- Angular Material Datepicker Disable Specific Dates Example
- Angular Material Datepicker Disable Previous Dates Example
- Angular Scroll to Top of Div Element Example
- Angular Google Maps with Places Search Example
- Angular 11/10 Select Dropdown Example Tutorial
- Angular 10 Image Upload with Preview Example
- Angular Call Component Method from Another Component Example