【发布时间】:2018-05-10 06:34:14
【问题描述】:
我正在尝试从父级调用我的子组件方法,但根本不起作用。
这是我的代码:
<router-outlet>
<app-modal-popup></app-modal-popup> //children for all pages!!
</router-outlet>
在首页:
import { Component, OnInit, Output, ViewChild, AfterViewInit } from '@angular/core';
import { ModalPopupComponent } from '../../shared/modal/modal-popup/modal-popup.component';
export class HomeComponent implements OnInit, AfterViewInit {
@ViewChild('appModal') private appModal : ModalPopupComponent;
footerLinkHandler(link){
console.log('link', link );
this.appModal.popMessage(link);
return false;
}
}
但收到Cannot read property 'popMessage' of undefined 的错误 - 有什么问题。但我从appModal 得到popMessage 自动填充。
【问题讨论】:
标签: angular