I have one method in Child component like below:
showAcknowledgement() {
this.noticeService.getNotice(ConstUrls.NoticeManagement.GetUserNotice).subscribe((data: any) => {
data.data.filter((res: any) => {
if (data.isSuccessful === true) {
this.noticeText = res.noticeText;
this.noticeAttachment = res.noticeAttachement;
this.noticeCode = res.noticeCode;
} else if (data.isSuccessful === false) {
this.message = [{ field: "", message: data.message[0].message }];
this.objError = this.message;
this.showError = true;
window.scrollTo({ top: 0, behavior: 'smooth' });
}
})
});
}
I need to call this method in parent component inside ngOnInit() because while page loading I need to call that method. I tried like below but its not working
Parent HTML:
<app-acknowledge-notice-modal #child></app-acknowledge-notice-modal>
Parent TS:
@ViewChild(AcknowledgeNoticeModalComponent, {static : true}) child : AcknowledgeNoticeModalComponent;
ngOnInit() {
this.child.showAcknowledgement();
}