Renato Souza de Oliveira
Renato Souza de Oliveira

Reputation: 4574

refresh component after request ajax

I tried the solutions to other questions, but they did not work

After inserting into my database I would like to update my component (The user needs to continue on the same component).

I tried to navigate to the component itself:

this.router.navigate(['/admin/product']);

I tried to go to another and go back to him:

this.router.navigate(['/admin']);
this.router.navigate(['/admin/product']);

None worked! I want the component to be reloaded to stay current with the database information. Does anyone know how to do this?

Upvotes: 1

Views: 857

Answers (1)

AVJT82
AVJT82

Reputation: 73357

Question not being entirely clear, but from what I understand:

"How to stay current with database information"

suggests to me that you do not need to reload your entire component, just make an api call to get the updated data. So after you had added data to your db, you just call to get the updated data. So dummy example would be:

addItem() {
  this.myService.addItem()
    .subscribe(data => {
       this.getAllItems(); // do the call here to update!
    });
}

Upvotes: 1

Related Questions