我正在使用带有延迟加载页面的 Ionic 3。尝试在页面内的组件中呈现模态时,出现以下错误:
No component factory found for CourseEditorComponent. Did you add it to @NgModule.entryComponents?
正如你在下面看到的,我已经将 CourseEditorComponent 作为 entryComponent 添加到 courses.modules.ts 中,它由 dashboard.modules.ts 导入。
我对自定义条目组件在 Angular/Ionic 中的使用方式有问题吗?
等级制度
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 {}
课程模块
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 存储库链接中报告了一个问题
使用EntryComponentsModule
导入EntryComponentsModule
(定义所有条目组件)以AppModule
,直到问题得到解决。
使用CourseEditorComponent
作为页面
将CourseEditorComponent
变成页面并将modal.create(CourseEditorComponent)
更改为modal.create('CourseEditorComponent')
你必须在 declarations[] 和 entryComponents 下添加它