Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
414 views
in Technique[技术] by (71.8m points)

javascript - 无法读取未定义的属性“ createComponent”(无解决方案)(Cannot read property 'createComponent' of undefined(No solution worked))

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...