angular - Ionic 3 open modal 出现未在入口组件中声明但已存在的错误
问题描述
我在 ionic 3 中有以下模式:
从'@angular/core'导入{ NgModule };从“离子角”导入{ IonicPageModule };从'./login-modal'导入{ LoginModalPage };
@NgModule({
declarations: [
LoginModalPage,
],
imports: [
IonicPageModule.forChild(LoginModalPage),
],
entryComponents: [LoginModalPage]
})
export class LoginModalPageModule {}
我想在 app.component.ts/html 中使用:
import { LoginModalPage } from '../modals/login-modal/login-modal';
import { LoginModalPageModule } from '../modals/login-modal/login-modal.module';
export function init_app(appLoadService: InitializerService) {
return () => {
return appLoadService.initializeApp();
}
}
@NgModule({
declarations: [
MyApp,
HomePage,
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp, {
preloadModules: true
}),
IonicPageModule.forChild(MyApp),
HttpClientModule,
LoginModalPageModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
GatewayService,
UserService,
GlobalVarService,
AuthGuardService,
HttpClient,
InitializerService,
{
provide: APP_INITIALIZER,
useFactory: init_app,
deps: [InitializerService],
multi: true
},
]
})
export class AppModule {}
但我收到以下错误:
core.js:1449 错误错误:未捕获(承诺中):错误:未找到 [object Object] 的组件工厂。你把它添加到@NgModule.entryComponents 了吗?错误:未找到 [object Object] 的组件工厂。你把它添加到@NgModule.entryComponents 了吗?
我尝试将其添加到 app.module.ts 的入口组件中,但出现以下错误:
LoginModalModule 在 2 个组件中声明
解决方案
为了在您的文件中使用它,AppComponent
您需要将它添加到您的declarations
文件中entryComponents
AppComponent.ts
将此添加到您的AppComponent.ts
,
declarations: [
MyApp,
HomePage,
LoginModalPage
]
entryComponents: [
LoginModalPage
]
将此添加到您的LoginPageModule
exports: [ LoginPageModal ]
根据entryComponents的定义
指定定义此模块时应编译的组件列表。对于这里列出的每个组件,Angular 都会创建一个 ComponentFactory 并将其存储在 ComponentFactoryResolver 中。
推荐阅读
- ffmpeg - 如何基于ffmpeg4.3.1设置h264_qsv编码器
- android - SensorManager.registerListener 导致应用程序崩溃
- fortran - 带有意图输出参数的 OpenACC 例程向量
- r - `group_by` 并将分组级别保持为嵌套数据框的名称
- flutter - 错误:无法解析“package:app/app_controller.dart”中的包“app”
- c++ - g++8.3 的模板替换错误
- openinventor - openinventor/coin3d如何实现像OpenGL一样的双面渲染?
- c# - 使用 Graph API C# 获取开放扩展
- java - 是否可以在 swagger 的 dataType 属性中使用可能的泛型?
- r - 如何将两行移动到 R 列表中数据框的顶部?