0

提交表单后,我的 HTML 组件更新出现问题。任何建议都会对我当前的代码有所帮助,以确保提交表单时它会更新正确的视图。刷新屏幕后,视图将更新为正确的信息;但这不是我想要的。

数据服务.ts

create(resource: any) {
return this.http.post(this.url, resource,
  {headers: this.header, responseType: 'text' as 'json'})

}

update(entryId: any, resource: any) {
return this.http.put(this.url + entryId, resource,
  {headers: this.header, responseType: 'text' as 'json'})

}

表格.ts

submit(resource) {
if (this.id) {
  this.service.update(this.id, resource)
    .subscribe(response => {
      console.log(response)
    });
    this.router.navigate(['../../'], {relativeTo: this.route});
}
else this.service.create(resource)
  .subscribe(response => {
    console.log(response)
    this.router.navigate(['../'], {relativeTo: this.route});
  })

}

前端视图.ts

ngOnInit(){

this.otherService.getAll()
  .subscribe(otherEntry => {
    this.otherEntry = otherEntry;
  });

}

4

0 回答 0