我正在将Ionic 3与延迟加载的页面一起使用。尝试在页面内的组件中显示模态时,出现以下错误:

No component factory found for CourseEditorComponent. Did you add it to @NgModule.entryComponents?


正如您在下面看到的那样,我已经将CourseEditorComponent作为entryComponent添加到Course.modules.ts中,并由dashboard.modules.ts导入。

我在Angular / Ionic中使用自定义entryComponents的方式有问题吗?

层次结构

DashboardPage
-CoursesComponent
--CourseEditorComponent
--CourseCreatorComponent
-InstructorsComponent


模组

dashboard.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { DashboardPage } from './dashboard';
import { CoursesModule } from "./courses/courses.module";

@NgModule({
  declarations: [
    DashboardPage
  ],
  imports: [
    IonicPageModule.forChild(DashboardPage),
    CoursesModule
  ],
})
export class DashboardPageModule {}


course.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { CoursesComponent } from './courses';
import { CourseEditorComponent } from "./course-editor/course-editor";

@NgModule({
  declarations: [CoursesComponent],
  imports: [IonicPageModule.forChild(DashboardPage)],
  entryComponents: [CourseEditorComponent],
  exports: [CoursesComponent,CourseEditorComponent]
})
export class CoursesModule {}


课程组成

import { Component } from '@angular/core';
import { ModalController } from 'ionic-angular';
import { CourseEditorComponent } from "./course-editor/course-editor";

@Component({
  selector: 'courses',
  templateUrl: 'courses.html',
})
export class CoursesComponent {
  editCourse(data) {
    let editor = this.modal.create(CourseEditorComponent,{course: data});
    editor.present();
  }
}

最佳答案

@NgModule({
  imports:      [ BrowserModule, FormsModule ],
  declarations: [ AppComponent, HelloComponent ],
  bootstrap:    [ AppComponent ],
  entryComponents: [your modal component] // you need to add it to entry component
})
export class AppModule { }


截至目前,没有对它的支持,Angular git repo LINK中报告了相同的问题

使用EntryComponentsModule

EntryComponentsModule(在其中定义所有entryComponents的位置)导入到AppModule,直到问题解决。

使用CourseEditorComponent作为页面

CourseEditorComponent转到页面,然后将modal.create(CourseEditorComponent)更改为modal.create('CourseEditorComponent')

09-05 23:16