7

For an ionic-3 project we are using LAZY LOADING. Our Module " LOGIN " is being lazy loaded. Everything works fine but when we try to use NAV CONTROLLER for navigating between pages INSIDE the LAZILY LOADED module - we get the RUNTIME ERROR "NO COMPONENT FACTORY"

Code Below

login.ts

import { Component } from '@angular/core';
import { IonicPage } from 'ionic-angular';
import { NavController } from 'ionic-angular';
import {DummyPage} from './dummy';

@IonicPage()
@Component({
  templateUrl: 'login.html'
})
export class LoginPage {

  

  constructor(public navCtrl: NavController) 
  {

  }

  buttonClick()
  {
      this.navCtrl.push(DummyPage)
  }

}

login.module.ts

import {ModuleWithProviders, NgModule, Optional, SkipSelf }       from '@angular/core';
import { CommonModule }      from '@angular/common';
import { IonicPageModule } from 'ionic-angular';
import {LoginPage} from './login';
import {DummyPage} from './dummy';

@NgModule({
  imports:      [ CommonModule, IonicPageModule.forChild(LoginPage) ],
  declarations: [LoginPage, DummyPage],
  exports:      [ LoginPage, DummyPage ],
  providers:    [  ]
})

/* core module is imported once and is made
applicable through the app. Application wide singleton services
like user authentication etc. are defined here */

export class LoginModule {
}

DUMMY.TS is the page that is INSIDE the LOGIN Module and I don't want to create a separate NG MODULe for it - hence using the navController. This how ever throws an error

import { Component } from '@angular/core';
import { IonicPage } from 'ionic-angular';
import { NavController } from 'ionic-angular';


@Component({
  template:'<h1> AWWWW </h1>'
})
export class DummyPage {

  

  constructor(public navCtrl: NavController) 
  {

  }

  buttonClick()
  {
    alert("Hello world");
  }

}

As seen above, I have added DUMMY.TS in the ngModule and entryComponents

The ERROR IS: Error Snippet

6
  • 1
    Havent tried this but try IonicPageModule.forChild(DummyPage) in imports Commented May 4, 2017 at 12:23
  • Works ! Thanks ! Commented May 4, 2017 at 12:25
  • 1
    alright.. adding as answer Commented May 4, 2017 at 12:25
  • Am sorry this solution feed the problem but added another. If I added IonicPageModule.forChild(DummyPage) it overwrites the LoginPage and doesn't let me load the LoginPage. Commented May 4, 2017 at 12:42
  • hmm.. I guess unless you set in app.module.ts, you cant add two pages in one page module.. Commented May 4, 2017 at 12:44

3 Answers 3

1

Solution was to add a reference to this page in app.module.ts and add it in referencing

    import {DummyPage} from './login/dummy';
@NgModule({
  declarations: [MyApp, DummyPage],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [MyApp, DummyPage],
  providers: [
    StatusBar,
    SplashScreen,
    { provide: ErrorHandler, useClass: IonicErrorHandler }]
})
export class AppModule { }

Guess Ionic is treating the DummyPage as a dynamic loaded page and we need to tell the app.module.ts to compile it offline and create a factory for it for using when required.

Sign up to request clarification or add additional context in comments.

2 Comments

I do have the same problem, but I thought one purpose of the new modules is that you dont have to add the page in the very top 'declarations' and 'entryComponents'. I dont think this is the right way to do it...
This works for an old project! However it is not necessary for newly created project with ionic 3.
1

You need to add a dummy.module.ts in the dummy folder, which will solve the problem.

Do take a look at the related github project.

1 Comment

I had the same issue. and it did cost me a lot of time. thanks for @laker's answer. it did help me a lot. Aactually. you just need to treat dummy as a module. then you can call the modal with the module-name pass to it. then everything just works fine.
-1

Have you tried call with strings ?

buttonClick() {
    this.navCtrl.push('DummyPage')
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.