当我从Angular 4中的父组件单击按钮时,我需要更新子组件中的Html表 .
My Parent component click event is below
Resetcount() {
if (this.step == "child") {
this.airportmgt.GetAllUserList();
}
}
My Child component
GetAllUserList() {
this.auth.Get(myurl).then((user) => {
let organisationDTOS = user.json();
this.Users = organisationDTOS.Users;
console.log(JSON.stringify(this.Users);
}).catch((e) => {
`enter code here`
this.toast.error(this.commethod.getErrorcodeStatus(e));
})
}
}
请注意,我在Html迭代中使用Users数组 .
2 回答
家长component.html
家长component.ts
机场mgt.service.ts
儿童component.ts
如果您发现任何困难,请告诉我,我将为您提供jsfiddle链接 .
使用
@viewchild()
concept来访问子组件中的方法示例:子组件 - persondetails.component.ts:
app.component.ts:
请参阅文档https://angular.io/guide/component-interaction#parent-calls-an-viewchild