我想在Ionic中打开一个模态:
export class TexteditorComponent {
function showFormulaEditor() {
this.modalCtrl.create({
component: FormulaCreatorComponent
}).then(m => m.present());
}
}
但是,执行此代码时,出现以下错误:
Error: "Uncaught (in promise): Error: No component factory found for FormulaCreatorComponent. Did you add it to @NgModule.entryComponents?
TexteditorComponent和FormulaCreatorComponent已在texteditor.module.ts中注册:
@NgModule({
declarations: [TexteditorComponent, FormulaCreatorComponent],
entryComponents: [TexteditorComponent, FormulaCreatorComponent],
imports: [
CommonModule
],
exports: [TexteditorComponent, FormulaCreatorComponent]
})
export class TexteditorModule { }
texteditor.module.ts导入到exercise.module.ts中:
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
TexteditorModule,
RouterModule.forChild(routes)
],
declarations: [ExercisePage, PatternedInputComponent]
})
export class ExercisePageModule {
constructor() {
console.log("ExercisePageModule init");
}
}
ExercisePage使用其选择器加载TexteditorComponent:
<app-texteditor [(ngModel)]="exercise.Exercise"></app-texteditor>
一切正常,TexteditorComponent正确呈现。
只有模态不会打开。 我在showFormulaEditor()中记录了modalCtrl: 肯定有FormulaCreatorComponent的工厂。
但是,以下代码返回未定义的
modalCtrl.resolver._factories.get(FormulaCreatorComponent)
尽管如此,我可以使用其选择器将FormulaCreatorComponent添加到TexteditorComponent中:
<app-formulacreator></app-formulacreator>
没有问题。
答案 0 :(得分:0)
我终于解决了... 在texteditor.component.ts中,我使用以下代码行导入了FormulaCreatorComponent:
import { FormulaCreatorComponent } from './formulacreator/formulacreator.component.js';
很明显,.js
不正确。无论如何,我的IDE(Visual Studio代码)都能识别它,并在单击“打开定义”时将我引到正确的目的地。