@angular/common/http has no exported member 'RequestOptions'
Asked Answered
A

1

6

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) })
    }
}
Amitie answered 30/12, 2018 at 18:43 Comment(2)
You are importing from wrong path: https://angular.io/api/http/RequestOptionsCharla
Indeed there is no such class in @angular/common/http. But you ain't using it anyway, so why do you import it?Mylesmylitta
R
10

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)
Rimester answered 31/12, 2018 at 14:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.