gpt4 book ai didi

angular - Angular|Ionic 中“未找到 [自定义组件] 的组件工厂”

转载 作者:行者123 更新时间:2023-12-02 21:28:33 25 4
gpt4 key购买 nike

我正在使用带有延迟加载页面的 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 中使用自定义 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 {}

类(class)组件

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 存储库中报告了相同的问题 LINK

使用EntryComponentsModule

EntryComponentsModule(定义所有 EntryComponent 的位置)导入到 AppModule,直到问题得到解决。

使用CourseEditorComponent作为页面

CourseEditorComponent变成页面,并将modal.create(CourseEditorComponent)更改为modal.create('CourseEditorComponent')

关于angular - Angular|Ionic 中“未找到 [自定义组件] 的组件工厂”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47122228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com