【发布时间】:2019-04-11 22:25:41
【问题描述】:
我们在应用程序中使用了模式 (ng-bootstrap's one)。该模态看起来像:
<ng-template #modal let-modal>
<app-audio #audio></app-audio>
</ng-template>
这是逻辑:
@ViewChild('modal')
modal: ElementRef;
@ViewChild('audio')
audio: AudioComponent;
模态打开方式:
this.modalService.open(this.modal, { size: 'lg' });
到这里为止一切都很好。模态打开并显示音频组件。但是现在,我们想要访问组件内部的逻辑,并且在执行以下操作时:
this.audio.somePublicComponentFunction()
恰好 this.audio 为空。我已经尝试让孩子使用 angular 的变化检测器,但找不到将 this.audio 与实际组件正确链接的方法。有任何想法吗?非常感谢。
You can see the issue here: stackblitz.com/edit/angular-ofmpju
【问题讨论】:
-
请提供minimal reproducible example 重现您的问题。
-
嗨@trichetriche,就这么简单。即使在打开模式并呈现内容后,我也无法引用音频组件。将 app-audio 留在模态之外时,一切正常。
-
我了解您的问题。我要求您在沙盒中提供一个示例。
-
不确定这是否有帮助。不过,还是想和大家分享一下。 stackoverflow.com/questions/41669787/…
-
抱歉@trichetriche,今天很忙。我在这里重现了这个问题:stackblitz.com/edit/angular-ofmpju
标签: javascript angular ng-bootstrap viewchild