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();
}
答案 0 :(得分:0)
“ this.router.navigate(['URL','Params']); ”