【发布时间】:2019-10-05 16:47:52
【问题描述】:
我应该在 Angular 中使用 httpclient 模块进行 post 调用,但在这种情况下调用没有执行,应该怎么办?
app.component.html:
<div class="col-xs-12">
<button class="btn btn-primary" (click)="getData()">Chiamata rest</button>
</div>
app.component.ts:
import { Injectable,Component, OnInit ,DoCheck} from '@angular/core';
import { HttpClient,HttpHeaders } from '@angular/common/http';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
getData(){
const body = JSON.stringify({firstName: 'Joele', lastName: 'Smith4'});
return this.http.post('http://localhost:8787/utente/nuovoutente', body, httpOptions);
}
【问题讨论】:
标签: angular post httpclient