@angular/common/http 没有导出成员 'RequestOptions'
@angular/common/http has no exported member 'RequestOptions'
我想使用 firebase 函数处理 angular 6 的电子邮件,但 angular 抛出此错误:
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 在“@angular/common/http”模块中不可用。它曾经在“@angular/http”模块中可用,现在已在最新的 angular 版本中弃用。您现在可以像这样创建局部变量 -
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
并且您可以在进行 http 调用时使用 httpOptions。
return this.http.get('PRODUCT_URL', httpOptions)
我想使用 firebase 函数处理 angular 6 的电子邮件,但 angular 抛出此错误:
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 在“@angular/common/http”模块中不可用。它曾经在“@angular/http”模块中可用,现在已在最新的 angular 版本中弃用。您现在可以像这样创建局部变量 -
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
并且您可以在进行 http 调用时使用 httpOptions。
return this.http.get('PRODUCT_URL', httpOptions)