Am having two components named AddPersons and PersonList. After adding a person in the AddPerson component, I am trying to refresh the PersonList component. For that I tried calling the ngOnInit() of PersonList component from AddPerson.
I am getting the updated data in PersonList but the list is not getting updated in html.
add-person-component.ts:
constructor(private personService: PersonService, private compPersonList: PersonListComponent, ) { }
onAddPerson(): void {
var modalContainer = "#add-person";
this.personService
.addPersons(this.name, this.age)
.subscribe(
response => {
if (response === true) {
this.compPersonList.ngOnInit();
$(modalContainer).modal('hide');
}
},
error => {
this.errorDetails = this.errorHandlingService.getErrorModel(error);
});
}
person-list-component.ts:
ngOnInit(): void
{
this.populateGrid();
}