0

我对 Angular 和 Angular 中的事件非常陌生。

我的父模板:

    <child1 (myEvent)="child2.testMethod()"></child1>
    <child2 #child2 *ngIf="show"></child2>

我收到“无法读取未定义的属性 'testMothod'”错误,但是当 child2 组件中的 *ngIf 被删除时,会调用“testMethod”方法。

演示:https ://stackblitz.com/edit/angular-1c8hfj

4

1 回答 1

1

这是一个已知的角度问题https://github.com/angular/angular/issues/6179

添加@ViewChild('child2') child2;AppComponent解决它。

于 2018-12-19T16:12:07.093 回答