Ste*_*ven 2 http jhipster angular
所以,我有一个Jhipster生成的应用程序.
在其中我们有许多实体,前端和后端都有"默认"方法
其中一个方法是create,在本例中是实体ActivePharmaIng,这是角度服务类中的代码:
create(activePharmaIng: ActivePharmaIng): Observable<ActivePharmaIng> {
const copy = this.convert(activePharmaIng);
return this.http.post(this.resourceUrl, copy).map((res: Response) => {
const jsonResponse = res.json();
return this.convertItemFromServer(jsonResponse);
});
}
Run Code Online (Sandbox Code Playgroud)
所以,这个代码就像它在实体区域中使用的魅力一样,但是,当我尝试在一个模态中重用它时,我从一个用(单击)调用的函数调用它,该函数的代码:
saveNewApi(api: ActivePharmaIng) {
this.activePharmaIngDTO.api = this.activePharmaIng;
this.activePharmaIngService.create(api);
this.show = false;
}
Run Code Online (Sandbox Code Playgroud)
在第二行中我们可以看到创建调用,在调试时我看到函数被无缝调用,并且只是在尝试执行调用后直接跳转到create函数
我没有任何错误消息的痕迹,没有使用IntelliJ调试,不是在谷歌开发人员工具栏中,在控制台和网络区域尝试,而不是单个消息.它只是跳转到下一行,这是一个布尔值,当设置为false时会隐藏表单的某些div:
如果您希望拨打电话,则必须订阅观察信息.此外,你应该很可能移动this.show = false;到可观察到的回调.
saveNewApi(api: ActivePharmaIng){
this.activePharmaIngDTO.api = this.activePharmaIng;
this.activePharmaIngService.create(api).subscribe(result => {
this.show = false;
});
}
Run Code Online (Sandbox Code Playgroud)
请参阅HttpClient文档:
请注意subscribe()方法.从HttpClient返回的所有Observable都很冷,也就是说它们是提出请求的蓝图.在调用subscribe()之前不会发生任何事情,并且每个此类调用都会发出单独的请求.例如,此代码发送两次具有相同数据的POST请求
| 归档时间: |
|
| 查看次数: |
1188 次 |
| 最近记录: |