Я построил угловую реактивную форму поверх REST API, и мне нужно отправить (POST) данные в 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: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>