I'm trying to load component depends on statement.The method createComponent()
is being considered as undefined on runtime I don't know why it happens.I used console.log(chart1)
to see its undefined or not and its undefined on the console.Thats my problem I guessI checked for some other solutions about this problem and didn't work for me
(我正在尝试加载依赖于语句的组件。方法createComponent()
在运行时被视为未定义,我不知道为什么会发生。我使用console.log(chart1)
来查看其未定义和未定义这是我的问题,我想我检查了有关此问题的其他解决方案,但对我不起作用)
Basically Im trying to load components responsible from generating chartJS chart.And when innerWidth
is less or equal than 991, component shouldnt be loaded.Thats my statement.I also added my component into entryComponents:[]
array.
(基本上,我试图加载负责生成chartJS图表的组件。当innerWidth
小于或等于991时,不应该加载组件。 innerWidth
是我的声明。我也将组件添加到entryComponents:[]
数组中。)
I can't show you whats inside chart component because thats very long page includes AfterViewInit()
method(For gradient color),json array for chart properties and data.
(我无法向您展示图表组件内部的内容,因为那很长的页面包括AfterViewInit()
方法(用于渐变颜色),图表属性和数据的json数组。)
Here what I tried below.
(这是我下面尝试的。)
App.Component.ts
(App.Component.ts)
@ViewChild('chart1', {read: ViewContainerRef,static:true}) chart1: ViewContainerRef;
chartGenerator() {
// Check requirements to show the survey
if ((window.innerWidth>=991)) {
// Resolve a factory
const surveyFormFactory = this.resolver.resolveComponentFactory(chart1);
const component = this.chart1.createComponent(surveyFormFactory);
}
}
ngOnInit{
this.chartGenerator();
}
App.Component.html
(App.Component.html)
<ng-container #chart1></ng-container>
ask by Timu?in ?i?ek translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…