从另一个组件调用时ngOnInit()不会刷新该组件

时间:2019-01-29 14:46:43

标签: angular modal-dialog ngoninit

Am具有两个名为AddPersons和PersonList的组件。在AddPerson组件中添加人员之后,我尝试刷新PersonList组件。为此,我尝试从AddPerson调用PersonList组件的ngOnInit()。

我正在PersonList中获取更新的数据,但是列表未在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();
}

1 个答案:

答案 0 :(得分:0)

  1. 控制器末端存在语法错误。 意外的“,”
  2. 而不是通过onOnit()调用另一个页面组件,请尝试

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