I’m going through the upgrade path to get to RC0 and whew, it’s a doozy. But right now I’m trying to understand the best practice for app.module. Looking at the ionic-conference-app as an example, it would seem as though every page in the app should go in both the declarations and entry components. And then every provider should go in the providers section. … And then we should no longer user the providers property when defining a component.
Is all of that correct? And if so, it is best practice, or should we have multiple modules in a project, separated by feature area (akin to modules in angular 1), and then import those feature modules into the app module with the imports property?
I have a similar question, but just revolving around entryComponents. I was under the impression that entry components was going to be deprecated in RC6+, but I guess it hasn’t been.
I also wonder this, would be great if the ionic team could give us an explanation of how we are supposed to use this new app structure with the NgModel and everything.
@gsoulie as far as I understood you don’t need to declare your providers in each page anymore. You actually can’t since ‘providers’ is not part of the object in ‘@Component’ anymore.
Now you just put them in the @NgModule object inside app.module.ts. They should be accessible all over your app. (Actually the module, but if you follow the migration guide your entire app will be inside one module).
Acording to Angular.io docs, the modules have to declare the providers and not the components unless you have a very good reason to hide the service to other components, making it lazy loaded, but you shouldn’t. As @MrFloppy says, all ngmodule providers become app-wide available anyway so having them inside the app.module should be ok. The injector handles this. Dependency injection
The thing I’m having a hard time to get is: how should we structure different features throughout the application? Should we have domain and routed feature modules as the NgModule FAQ says? feature-modules. And if so:
How to import and navigate to different modules? (If I add another module to the app.module imports as Angular.io examples, IonicModule seems to stop working)
I created an ionic2.rc0 project using angular2 modules structure.
It’s based on the blank project.
The only thing I don’t like, is how to navigate between modules.
Thanks for the explanations! Sounds very logical to me!
Do you have any reference to best practice for the actual codes of how to transition between modules? is it using navController’s setRoot, setPage? Thanks
Well i have the same question, i think it was partialy solved here, just dont get it the diference on “declarations” and “entryComponents”, and why everything is on both decorators.
I like the idea of structuring an app in different modules as @JumBay shows in the link.
As long as ionic 2 does not support lazy loading it should be not that much of a problem, but as soon as it does, you get different instances of services (“providers”) that should be singletons because you have to import IonicModule into every of your modules.
In addition IonicModule reexports BrowserModule into every of your modules that need ionic directives or components although angular docs recommend to import BrowserModule only once in your RootModule and use CommonModule instead in each of your other modules.
This is for dynamically added components that are added using ViewContainerRef.createComponent(). Adding them to entryComponents tells the offline template compiler to compile them and create factories for them.
The components registered in route configurations are added automatically to entryComponents as well because router-outlet also uses ViewContainerRef.createComponent() to add routed components to the DOM.
Defines the components that should be compiled as well when this component is defined. For each components listed here, Angular will create a ComponentFactory and store it in the ComponentFactoryResolver.
If you don’t list a dynamically added component to entryComponents you’ll get an error message a bout a missing factory because Angular won’t have created one.