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