@angular/common/http has no exported member 'RequestOptions'
15,864
RequestOptions is not available in "@angular/common/http" module. It used to be available in "@angular/http" module which has now been deprecated in latest angular versions. You can now create a local variable like this -
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
And you can use httpOptions while making an http call.
return this.http.get('PRODUCT_URL', httpOptions)
Related videos on Youtube
Author by
Akcil
Updated on June 04, 2022Comments
-
Akcil almost 2 years
I want to sand emails with angular 6 using an firebase function, but angular throws this error:
error TS2305: Module '"E:/project/node_modules/@angular/common/http"' has no exported member 'RequestOptions'.
import { Injectable } from '@angular/core'; import { NgForm } from '@angular/forms'; import { HttpClient, HttpHeaders, RequestOptions } from '@angular/common/http'; import 'rxjs'; @Injectable() export class MailerService { constructor(private httpClient: HttpClient) { } send(form: NgForm) { let url = 'TheUrlOfMyFunction'; let params: URLSearchParams = new URLSearchParams(); let options = {headers: new HttpHeaders({'Content-Type': 'application/json'})}; params.set('to', form.value['emailTo']); params.set('from', form.value['emailFrom']); params.set('subject', form.value['object']); params.set('content', form.value['text']); return this.httpClient.post(url, params, options) .toPromise() .then( res => { console.log(res) }) .catch(err => { console.log(err) }) } }
-
Harun Yilmaz over 5 yearsYou are importing from wrong path: https://angular.io/api/http/RequestOptions
-
JB Nizet over 5 yearsIndeed there is no such class in @angular/common/http. But you ain't using it anyway, so why do you import it?
-