Modular App Structure with Ionic 2


I would like to build a very large application for multiple platforms with ionic 2 (ios, android, pwa, etc). For developing with a team it would be nice to include the style guide and recommendations for angular 2 (

The documentation for angular 2 recommends to provide services in AppModule and to not load them multiple times. I would like to group pages in different modules, but to use components from ionic 2 I have to import IonicModule into every module that uses them, but ionic 2 does not provide a module only containing the pipes, directives and components. It has only its IonicModule, that exports for example BrowserModule. But BrowserModule should be imported only into AppModule and nowhere else. In other modules the recommendation is to import CommonModule instead of BrowserModule.

Does somebody has a suggestion how to solve this in a good way?

1 Like

I suppose you googled it already? Are there already Ionic 2 “starters”, like there were many “starters” for Ionic 1 ?

Yes I googled it, but have not found anybody mentioning this topic. All starters I found use a project structure I would like to avoid: All Services in a folder called providers, all pages in a folder called pages and only one module. It would be nice, if there would be an IonicModule.forChild() method, that returns a module containing only the declarations and entryComponents

Try this:

Hi @SslayerRfla and thanks for sharing.
How does the blogpost concern my question? I don’t find anything about modular structure in it.

Oops, I’m sorry, I probably replied in the wrong post by having more than four browser tabs open on different subjects.

@Nexi Have you found anything?

Yes. They changed the BrowserModule to CommonModule. So an import of IonicModule should not be a big problem. Just skip the forRoot in your child modules. I guess it would work now. But there is no chance for completely lazyloading these modules. Only Pages can be lazyloaded by use of the new IonicPageModule-Feature.

I found an interesting article about this topic. The author says that he had heared from the ionic team, that they are working on allowing feature oriented lazy loading: