0

I am having issues with my HTML components updating after a form is submitted. Any suggestions would be helpful on my current code to make sure when a form is submitted it updates the correct view. The view will update with the correct information once I refresh my screen; however that is not what I want.

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;
  });

}

Rob DePietro
  • 284
  • 2
  • 8
  • 23
  • What route is `['../../']`? This is not file path route, it is your route you define on your routing for angular. – penleychan Mar 05 '19 at 20:37
  • This is used for when the when the form is submitted to go back previous view or the view that is relative to this.route ex: www.website.com/ogoing/id/form when its submitted it will go back to www.website.com/ongoing – Rob DePietro Mar 05 '19 at 20:39
  • 1
    Yes but pretty sure you need something else along with that, see https://stackoverflow.com/a/38634440/6736888 – penleychan Mar 05 '19 at 20:41

0 Answers0