【发布时间】:2018-08-30 22:33:04
【问题描述】:
我使用“ng generate library”命令创建了一个 Angular 6 库。该库在 --prod build 之后在我的基础组件中使用,然后在主应用程序的 app.module.ts 中导入。库中的...组件文件有@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 是未定义的。但我可以看到 this.leftPanel 指向 div。想知道为什么即使 @Input leftPanel 是“ElementRef”类型,它也不允许 this.leftPanel.nativeElement`?
提前致谢!
【问题讨论】: