Reputation: 3542
First of all, it's not a duplicate of any other question and I've read the angular guide on that. However I still have several questions.
The feature module is the easiest one - you have a feature - group it into feature module. Let's say that in addition to obvious feature I have the pages which every application has:
I could probably move everything to feature module called 'static' but I don't like the name and also don't like grouping mostly unrelated things into the same module, i.e. error page and contact page. So, what is a pattern for mentioned pages?
Now, shared vs core module. I have the following items:
So, the main question is how to choose decide for the items I listed and for new items like those.
Upvotes: 38
Views: 22926
Reputation: 41274
The answers to your question are subjective, however there are some recommendations from official docs you can follow: What kinds of modules should I have and how should I use them?. If you haven't read docs on NgModule
and FAQ, I'd suggest spending a few hours studying them, things will be much clearer (at least they were for me :)
I'm using the following setup and it works quite well for me:
directives
, components
and pipes
, just to keep things organized a little better. Examples: filesize.pipe
, click-outside.directive
, offline-status.component
...about.component
, contact.component
, app-toolbar.component
ui.service
, auth.service
, auth.guard
, data.service
, workers.service
....user-profile.component
, dashboard.component
, dashboard-sidebar.component
...player
, playlist
, favorites
submodules would go. If you look at the @angular/material2
this would be an equivalent to their MaterialModule
and many submodules, like MdIconModule
, MdSidenavModule
etc. General advice would be:
To answer your specific questions: I would put all those routes in one module - static
, public
, whatever the name. CsrfService
- core, Logger
- core or dev, HttpModule
- core, you only need one instance (probably), auth
- core. Don't put services in shared.
If you can't decide how/what to group in a feature, make a new app, copy specific feature folder and it should work there as well. If it doesn't, you'll need to organize things better.
Upvotes: 90