我使用“ng generate library”命令创建了一个 Angular 6 库。该库在 --prod build 之后在我的基础组件中使用,然后在主应用程序的 app.module.ts 中导入。库中的 ...Component 文件有@Input("leftPanel") leftPanel: ElementRef;
base.component.html 上的 HTML Div 元素如下所示:<div #leftPanel></div>
库元素使用其选择器:
<lib-ng-mylibrary [leftPanel]="leftPanel"> </lib-ng-mylibrary>
库组件实现 AfterViewInit。在实现方法中,这段代码执行失败:this.leftPanel.nativeElement.style.flexBasis = '50%';
它说,this.leftPanel.nativeElement is undefined。但我可以看到 this.leftPanel 指向 div。想知道为什么即使@Input leftPanel 是'ElementRef'类型,它也不允许this.leftPanel.nativeElement`?
提前致谢!