I have a component with a table that show rows from database. This component also has a "Add" button.
When I click on this button a modal appears with a form to add a new entry in the database.
I can save the row to the database, but I want to refresh the table in the parent component to show the new added entry.
The code I am using is:
in the parent component I open the modal with:
<div>
<a href="#responsive-modal" data-toggle="modal" data-target="#responsive-modal" class="btn btn-md btn-add animated flipInX flipInY lightSpeedIn slideInUp" (click)="createAgentie(agentie2)"><i class="fa fa-plus"></i> Add</a>
<createagentie></createagentie>
</div>
ts:
@ViewChild(CreateAgentieComponent) createAgentie: any = {};
CreateAgentiee(agentie2: any = {}) {
this.createAgentie.myObject = agentie2;
this.createAgentie.open();
}
in the child component:
<button type="button" (click)="submit()" class="btn btn-danger waves-effect waves-light" data-dismiss="modal">Save changes</button>
ts:
submit() {
this.createagentieService.create(this.myObject)
.subscribe(x => {
console.log(x);
this.myObject.denumire = "";
this.router.navigate(['/vizualizareagentii']);
});
}
The problem is that this.router.navigate(['/vizualizareagentii']); which is the parent component's route does nothing. How can I go the parent component and refresh it?