0

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();
}
georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • fiiiirst of all, in no case ever do you call `OnInit` manually. Secondly, check component interaction: https://angular.io/guide/component-interaction#component-interaction – AT82 Jan 29 '19 at 19:18

1 Answers1

0
  1. there is syntax error at end of your controller. Unexpected ','
  2. instead of calling another page component through onOnit() try

"this.router.navigate(['URL','Params']);"

Monkey D. Luffy
  • 181
  • 1
  • 3
  • 16