使用p3x-angular-compiler时,组件中的参考模板变量未定义

时间:2019-06-06 18:18:13

标签: angular p3x-angular-compile

我正在使用p3x-angular-compiler plugin,并且我的html中有一个引用变量,因此我试图在组件中获取它。

HTML-

<div #scrollMe></div>

ts-

@ViewChild('scrollMe') private chatScrollContainer: ElementRef;

当我在this.chatScrollContainer中管理ngOnInit时,我不确定。

2 个答案:

答案 0 :(得分:0)

尝试将代码从ngOnInit移至ngAfterViewInit

答案 1 :(得分:0)

我知道这个线程很旧,但原因是 p3x-angular-compile 创建了一个组件,其中包含一个上下文对象,其中包含您的变量。

您应该在模板变量前加上“上下文”。

{{context.foo}}