【发布时间】:2021-10-27 22:06:43
【问题描述】:
我在子组件中有一种方法,如下所示:
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' });
}
})
});
}
我需要在 ngOnInit() 内的父组件中调用此方法,因为在页面加载时我需要调用该方法。我尝试如下,但它不起作用
父 HTML:
<app-acknowledge-notice-modal #child></app-acknowledge-notice-modal>
父 TS:
@ViewChild(AcknowledgeNoticeModalComponent, {static : true}) child : AcknowledgeNoticeModalComponent;
ngOnInit() {
this.child.showAcknowledgement();
}
【问题讨论】:
标签: angular typescript