是否可以在离子3中的非延迟加载页面中制作延迟加载组件?

时间:2018-03-14 13:46:55

标签: angular typescript ionic-framework ionic3

我已多次尝试在非延迟加载页面中延迟加载组件,但这给了我一个错误

// app.module.ts

import {LoginPage} from '../pages/login/login';

@NgModule({
  declarations: [
    MyApp,
    LoginPage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    HttpClientModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    LoginPage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler},

  ]
})

// login.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { LoginPage } from './login';
import {LoginFormComponent} from '../../components/login-form/login-form';

@NgModule({
  declarations: [
   LoginPage, 
   LoginFormComponent
  ],
  imports: [
    IonicPageModule.forChild(LoginPage),
  ],

})
export class LoginPageModule {}

这给我一个错误

please add a @pipe/@directive/@component annotation.

如果可能的话,如何在非延迟加载页面中创建延迟加载组件?

1 个答案:

答案 0 :(得分:0)

在Angular中,组件只能在一个模块中注册。

LoginPagedeclarations[]移除entryComponents[],然后从app.module.ts

中删除导入内容
@NgModule({
  declarations: [
    MyApp
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    HttpClientModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler},

  ]
})