'在Angular | Ionic中找不到[自定义组件]的组件工厂

时间:2017-11-05 13:39:48

标签: angular ionic-framework ionic2 ionic3

我正在使用带有延迟加载页面的Ionic 3。当试图在页面中的组件中呈现模态时,我得到以下错误:

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

正如您在下面所见,我已将CourseEditorComponent作为entryComponent添加到 courses.modules.ts ,它由 dashboard.modules.ts 导入。< / p>

我是否在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 {}

CourseComponent

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();
  }
}

2 个答案:

答案 0 :(得分:3)

@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')

答案 1 :(得分:2)

你必须在声明[]和entryComponents

下添加它