提交表单后,我的HTML组件更新出现问题。任何建议都会对我当前的代码有所帮助,以确保提交表单时它可以更新正确的视图。刷新屏幕后,视图将以正确的信息更新;但是那不是我想要的。
data.service.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'})
}
form.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});
})
}
frontendView.ts
ngOnInit(){
this.otherService.getAll()
.subscribe(otherEntry => {
this.otherEntry = otherEntry;
});
}