Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular 6 or 7: How to import RequestOptions and ResponseContentType in '@angular/common/http'

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';
like image 766
Amol B Lande Avatar asked Nov 02 '18 12:11

Amol B Lande


People also ask

What is httpclient API in angular 12?

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.

How to make GET POST PUT and DELETE requests in angular 12?

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:

How to start the HTTP service in angular?

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.

How to enable navigation in angular?

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:


1 Answers

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)
  )
);
like image 102
Sachin Shah Avatar answered Sep 22 '22 07:09

Sachin Shah