You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the standalone application schema, we are minimizing the use of modules only for situations where we need to group together components and directives
We are no longer supposed to use modules for
Components that are by nature standalone (for example the root component, and complete pages)
providers and setup of the root injector
In cases when we need to import a set of providers, we do it by calling a function that returns the providers, instead of importing a module.
Examples:
The router is configured using provideRouter()
The http is configured using provideHttpClient()
If we still need to import providers from a module, we can use the importProvidersFrom(module) function
We should only import modules for the components, directives and pipes in them.
Setting up the router
The router is a special module becuase it contains both template items (directives) and providers.
It is now split into 2 parts:
If you want to set up the router, instead of using RouterModule.forRoot(routes) or RouterModule.forChild(routes) you simply call the function provideRouter(routes)
If you want to use the directives, you need to import the module itself: imports: [RouterModule]
Of course, since all the directives are also standalone, you can simply imports: [RouterOutlet, RouterLinkDirective]
When you use a standalone component as a page to route to (which is recommended), you can load it lazily using the loadComponent function:
If you want to lazy-load a collection of child routes (which was the only option in the older version of angular) you can still use loadChildren but instead of passing a module file as parameter, you simply pass a file that contains an array of routes