Angular 如何将反应式表单数据发布到RESTAPI
我在RESTAPI之上构建了一个表单,我需要将数据提交(发布)到API 这是我在服务类中的POST函数Angular 如何将反应式表单数据发布到RESTAPI,angular,typescript,rest,Angular,Typescript,Rest,我在RESTAPI之上构建了一个表单,我需要将数据提交(发布)到API 这是我在服务类中的POST函数 postHotel(h :Hotel) { var body = JSON.stringify(h); var header = new header({'content-type' : 'application/json'}); var request = new RequestOptions({method: RequestMethod.Post , headers
postHotel(h :Hotel) {
var body = JSON.stringify(h);
var header = new header({'content-type' : 'application/json'});
var request = new RequestOptions({method: RequestMethod.Post , headers:header});
return this.http.post('http://localhost:56229/api/Hotels' ,body,request).map(x => x.json());
}
这是我的表格
<form [formGroup]="profileForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<div class="form-group col-md-6">
<label >Hotel Name</label>
<input class="form-control" type="text" formControlName="HotelName" required>
</div>
<div class="form-group col-md-6">
<label >Owner Name</label>
<input class="form-control" type="text" formControlName="OwnerName" required>
</div>
</div></form>
酒店名称
所有者名称
您可以使用被动表单的value属性
this.API.postHotel(this.profileForm.value)代码>