gpt4 book ai didi

angular - 尝试从 '@angular/common/http' 导入 import { HttpClient, Headers, RequestOptions } ;

转载 作者:行者123 更新时间:2023-12-04 12:38:47 24 4
gpt4 key购买 nike

我正在使用 ionic 4 项目。现在我正在尝试制作一个 http 帖子,并且我正在关注此链接上的 tut:https://www.techiediaries.com/ionic-http-post/ .现在说他在@angular/common/http'中找不到Headers、RequestOptions;

我尝试了不同的东西,我发现堆栈溢出。

import { Component, OnInit } from '@angular/core';
import { HttpClient, Headers, RequestOptions } from
'@angular/common/http';

@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit {

constructor(public httpClient: HttpClient) {
}
ngOnInit(){}

sendPostRequest() {
var headers = new Headers();
headers.append("Accept", 'application/json');
headers.append('Content-Type', 'application/json' );
const requestOptions = new RequestOptions({ headers: headers });

let postData = {
"name": "Customer004",
"email": "customer004@email.com",
"tel": "0000252525"
}

this.http.post("http://127.0.0.1:3000/customers", postData, requestOptions)
.subscribe(data => {
console.log(data['_body']);
}, error => {
console.log(error);
});
}

最佳答案

嗨,试试这个,而不是使用 HttpHeaders 的 header :

import { HttpClient, HttpHeaders , RequestOptions } from '@angular/common/http';

关于angular - 尝试从 '@angular/common/http' 导入 import { HttpClient, Headers, RequestOptions } ;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58431838/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com