【发布时间】:2020-12-17 13:09:32
【问题描述】:
我需要帮助将表单输入映射到我的界面,以便我的发布请求的正文看起来像这样。
"ListCars": [
{
"Car": "Toyota",
"Color" : "Red" ,
"Year": "2015"
}
],
"Type" : "rav4",
}
我目前正在从我的表单中获取此输出
Car: Toyota
Color : Red
Year: 2015
Type : rav4
这是我的界面示例
expand interface Cars
{
ListCars: ListCars[],
Type: string ;
}
这就是我从表单中获取值并提出请求的方式
组件.ts
this.FormGroup = this.formBuilder.group({
Car: new FormControl('', Validators.required),
color: new FormControl('', [Validators.minLength(5), Validators.required]),
year: new FormControl('', Validators.required),
type: new FormControl('', Validators.required),
});
submit(){
if (this.reproGroup.valid) {
const formValue: CarsInterface = this.FormGroup.value;
this.service.postrequest(formValue.)
.subscribe(response =>
{
});
}
}
service.ts
这就是我的发布请求的样子
postrequest(carsInterface : CarsInterface ): Observable< output> {
return this.http.post<output>(this .massReproDCQouteUrl, JSON.stringify(carsInterface ),
{
headers: {
'Content-Type': 'application/json'
}
});
}
【问题讨论】:
标签: angular forms api interface mapping