@ angular / common / http没有导出的成员'RequestOptions'

Akc*_*cil 2 angular angular-httpclient

我想使用Firebase函数使用角度为6的电子邮件打磨电子邮件,但是角度引发此错误:

错误TS2305:模块'“ E:/ project / node_modules / @ angular / common / http”'没有导出的成员'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) })

    }
}
Run Code Online (Sandbox Code Playgroud)

Sac*_*har 5

RequestOptions在“ @ angular / common / http”模块中不可用。它以前在“ @ angular / http”模块中可用,现在已在最新的angular版本中弃用。您现在可以像这样创建局部变量-

  const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type':  'application/json'
    })
  };
Run Code Online (Sandbox Code Playgroud)

您可以在进行http调用时使用httpOptions。

return this.http.get('PRODUCT_URL', httpOptions)
Run Code Online (Sandbox Code Playgroud)