Ionic 2 pagemodule lazyloading

0

Good morning everyone, I have generated a new project (blank) of ionic after updating everything.

I add a page (HomePage) with the cli generator, and I put it as a start page in app.components.ts but when doing ionic serve I get an error:

Uncaught (in promise): Error: No component factory found for HomePage. Did you add it to @ NgModule.entryComponents? noComponentFactoryError @ link

It only works if I include in app.module.ts in declarations and entry components HomePage, which I see, should not be given that the HomePage already has its start.module.ts

Any ideas?

Good @PabloLozano, I try to add the module in my app.components.ts:

import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';

import { MyApp } from './app.component';
import { InicioPageModule } from '../pages/inicio/InicioPageModule';

@NgModule({
  declarations: [
    MyApp,
  ],
  imports: [
    BrowserModule,
    HttpModule,
    InicioPageModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

But I get this error:

  

Typescript Error Can not find module   '../ pages / home / HomePageModule'.

    
asked by fmg 02.10.2017 в 11:42
source

1 answer

0

Good morning,

when you declare a page with lazy loading you can not treat it as a component and you have to treat it as a string.

It is an Ionic ñapa to distinguish the two cases.

use quotes.

rootPage:any = 'HomePage';

instead of the component.

they explain it well in the blog: link

For the same navigation.

this.nav.setRoot('TuPaginaConLazy');

instead of

this.nav.setRoot(TuPaginaSinLazy);
    
answered by 02.10.2017 / 13:04
source