I have migrated angular 4 code to angular 6 and I want to know how to import below code in angular 6 or 7?
import { RequestOptions, ResponseContentType } from '@angular/common/http';
This step by step guide helps you ascertain the usage, implementation, on top of that, the benefits of HttpClient API in the Angular 12 application. It also enables you to answer how to make HTTP (HTTP POST, GET, PUT, and DELETE) Requests. Angular is a powerful and profound framework to makes the frontend job easy for frontend developers.
Making GET, POST, PUT, and DELETE requests in Angular 12 with HttpClient API. First and foremost, download and establish Node on your development system: Install Angular CLI, Before you create a new angular application:
To start using the http service, we need to import the module in app.module.ts as shown below − If you see the highlighted code, we have imported the HttpModule from @angular/http and the same is also added in the imports array.
To enable the navigation add the router-outlet directive in app.component.html file: We will explain to you how to import and inject HttpClientModule in the Angular application. Import the HttpClientModule from the ‘@angular/common/http’ library. Also, import and register and FormsModule in the same file:
Pass this way ...
import { HttpClient, HttpHeaders } from '@angular/common/http';
let headers = new HttpHeaders({
'Content-Type': 'application/json'
});
let options = {
headers: headers
}
this.http.post(URL, param, options)
.subscribe(data => {
console.log(data);
});
// For pass blob in API
return this.http.get(url, { headers: new HttpHeaders({
'Authorization': '{data}',
'Content-Type': 'application/json',
}), responseType: 'blob'}).pipe (
tap (
// Log the result or error
data => console.log('You received data'),
error => console.log(error)
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With