Ionic 3 open modal 出现未在入口组件中声明的错误,但它已经存在

Ionic 3 open modal is getting an error of not declared in entry component but it is already exist

我在 ionic 3 中有以下模态:

从'@angular/core'导入{NgModule}; 从 'ionic-angular' 导入 { 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 ERROR Error: Uncaught (in promise): Error: No component factory found for [object Object]. Did you add it to @NgModule.entryComponents? Error: No component factory found for [object Object]. Did you add it to @NgModule.entryComponents?

我试图将其添加到 app.module.ts 的入口组件中,但出现以下错误:

LoginModalModule is declared in 2 components

为了在 AppComponent 中使用它,您需要将它添加到您的 declarationsentryComponents 文件中 AppComponent.ts

将此添加到您的 AppComponent.ts

declarations: [
  MyApp,
  HomePage,
  LoginModalPage
]

entryComponents: [
  LoginModalPage
]

将此添加到您的 LoginPageModule

exports: [ LoginPageModal ]

根据entryComponents的定义

指定定义此模块时应编译的组件列表。对于此处列出的每个组件,Angular 将创建一个 ComponentFactory 并将其存储在 ComponentFactoryResolver 中。