Ionic 2... now 3... UGH... PLEASE, NEED HELP with Modules

UPDATE: Thanks to @LoLStats, it is now clear how to properly import pages in such a way that implements lazy loading, see his post here: Ionic 2... now 3... UGH... PLEASE, NEED HELP with Modules


I get that Ionic 3 is still in beta … but with all due respect … it is beginning to feel like we will always be in beta … and our team DESPERATELY would like to get started on a new real world project…

we would LOVE to go with Ionic … but everything continues to change far to rapidly without enough instruction …

We would like to be able to use modules for the purposes of separating out features within our app in that we would like to know that lazy loading is going to work in Ionic …

THE PROBLEM: note, v 3.0.1 is currently set in our package.json file … When generating a new ‘test’ page via the CLI … we get the new test.module.ts file as expected but there is zero instruct on how to instantiate a module within ionic.

We tried the following:

import { TestPageModule } from '../pages/test/test.module'; // new test module generated by the cli

import { MyApp } from './app.component';

@NgModule({
  declarations: [MyApp],
  imports: [
    BrowserModule,
    TestPageModule, // i attempt to import it here
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [MyApp],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

Now there is zero instruct on how to set our root page as this new Test Module … attempting to set the module as the root page just throws the following error which obviously needs to be corrected since our new Module is not a component:

No component factory found for TestPageModule. Did you add it to @NgModule.entryComponents?

Why would we add it to entry components? It is not a component … of course attempting to try that anyway also throws an error:

TestPageModule cannot be used as an entry component.

Now i get it … Ionic works differently in that it does not use the Angular router … and it SEEMS like the right approach is just to import the Test page and not the module?? but it is not clear on whats happening here…

So our questions are:
How is lazy loading going to work?
What purpose does this new .module file serve exactly?
And how do we correctly work with modules in Ionic 3? What if we want to create our own?

Guys … ANY HELP every so GREATLY appreciated … UGH… Apologies if i sound frustrated … but this is now the third time we are starting from scratch on a project.

This error probably has something to do with you TestPageModule. I have my app setup with Modules by import the IonicModule in each module. By the way I believe Ionic 3 is actually released. I would check the links below about the lazy loading.


Thank you for responding …

Our TestPageModule file is OK, we had already fixed the problem where we had to change IonicModule to IonicPageModule in-order to correct the Module and remove the error… there is just no instruction on how to use this or any module for that matter in ionic 3…

Can you provide any example showing me how you created a module and how you included it in your project??

How do you use IonicModule? And whats the difference between IonicModule and IonicPageModule?

UGH this is beginning to get confusing. :frowning:

The CLI version 3 is in beta. The framework version 3 is not. If you’re running CLI v3, revert back, it’s not stable. For reference, I’m in Framework 3.0.1 and CLI 2.2.2. You might want to post your ionic info here, so posters can take a look.

THANK you for this response …

    Cordova CLI: 6.5.1-nightly.2017.4.21.72008357 (cordova-lib@6.5.1-nightly.2017.4.21.8030d2af) 
    Ionic Framework Version: 3.0.1
    Ionic CLI Version: 3.0.0-beta7
    ios-deploy version: 1.9.1 
    ios-sim version: 5.0.13 
    OS: macOS Sierra
    Node Version: v7.9.0
    Xcode version: Xcode 8.3 Build version 8W120l

I assumed we should be using the new CLI in-order for it to work properly with an ionic 3 project.

The old CLI does not create these new .module.ts files …

We are desperately trying to get to a place to start work on a new real world project … so if there is yet another major change coming in the way ionic instantiates pages ala this new .module.ts file, we would like to use the new CLI to avoid having to update our project AGAIN down the line here …

It is not clear as to how the new .module.ts file is used in conjunction with a “page”… from the looks of things … the file is not included anywhere in the project when its generated … and if we include it, there is no instruction on how to navigate to it …

And separately, what if we need to create our own modules?

Is it correct to assume that Ionic has no need for modules? That modules do not work and / or should not be used within an Ionic project?

We are just trying to understand so we can avoid difficult refactoring down the road… ugh.

A few of the more knowledgeable posters here recommend never using the CLI generators, instead setting up folders according to Angular recommendations. I use generators because I started using them on this project when I was more naive, and I don’t want to overhaul the structure in the middle of the process. If you’re starting a brand new project, though, you should give serious thought to whether you want to use the CLI generators. Once I’ve shipped the alpha of the project I’m working on right now, I’m going to re-evaluate my use of the CLI.

CLI 2.2.X create the module.ts files :wink:

And I created an upgrade guide for Ionic 3.0 Guide: How to update to Ionic 3.X
At the end, you find the lazy loading instructions: https://docs.google.com/document/d/1vGokwMXPQItZmTHZQbTO4qwj_SQymFhRS_nJmiH0K3w/edit

2 Likes

I understand what you are saying, but ionic does away with the Angular Router and has it’s own way of navigating …

Using the CLI i would hope would ensure that we are creating “pages” in the way they should be created for use within ionic …

The problem however is simply…

A: it is not clear what purpose the new .module.ts file serves … ie. its not included anywhere and can technically be deleted ??

B: Is it correct to say that we should not be creating Modules for use as a PAGE … that maybe its OK to create modules for use in part of a page, but there is no instruction on how to create a module and navigate to it directly.

I saw someone post (and I tend to agree) that the Ionic team put together the CLI with the development of small apps in mind. Something more “industrial size” – say 50 pages and 50 components – might benefit from a more categorized approach to folders. (Everything for user profiles goes here, everything for office supply products goes there.) So it depends what you want to use Ionic for.

1 Like

THANK YOU … reading through this now … albeit a little bit confusing …

So with all of that said though … should we not be creating modules? Is it correct to say that it is impossible to navigate to a Module in Ionic?

1 Like

You can ignore them actually because there are some problems with lazy loading pages (white screen at the start for example).

I will update my guide later to explain the lazy loading modules and how to update Ionic 2 pages.

1 Like

Thank you again for such a quick response… believe me i can understand what you all might be going through in trying to keep up with the Angular team … These releases are driving us crazy …

Part of our team is beginning to push for us to just role with Angular and Cordova because of Ionic’s current state …

If i can show them clearly what you all are going for i can convince them otherwise … i love and am fighting for us to be able to go with Ionic as our framework.

OK … that document was EXCELLENT, again, THANK you … now i get it … the only thing thats not entirely clear is, and i expect this is what you still need to complete, but its the part about creating a single components.module … and same for pipes using a pipes.module and so on … i look forward to seeing this updated…

We are going to go ahead with ionic … man … i hope this does not come back to bite us.

I should say … i am making the decision and telling our team that we are going with ionic … hah… Please wish us luck!! And thank you all for all your hard work.

IMHO, if you have an app that cares about those things - IOW, you are reusing custom components and pipes in many different pages - I would recommend not getting involved with lazy page loading due to code duplication concerns. It is perfectly possible to delete all ‘[page].module.ts’ files, take the @IonicPage decorator off of all your pages, navigate using class constructors instead of strings, and putting everything into a single app module as has been done before. At least do this so you have benchmarks for app binary size and loading speed before you start experimenting with lazy page loading.

If you insist on sticking with lazy page loading, you don’t need to worry about importing page modules. Just change all your navigation interaction to use strings and the lazy page loader will take care of loading your page module on demand.

1 Like

Within your my-page.module.ts, add to NgModule’s imports ComponentsModule which is from …/…/components/components.module

1 Like