{ "id": "guide/ngmodules", "title": "NgModules", "contents": "\n\n\n
NgModules configure the injector and the compiler and help organize related things together.
\nAn NgModule is a class marked by the @NgModule
decorator.\n@NgModule
takes a metadata object that describes how to compile a component's template and how to create an injector at runtime.\nIt identifies the module's own components, directives, and pipes,\nmaking some of them public, through the exports
property, so that external components can use them.\n@NgModule
can also add service providers to the application dependency injectors.
For an example app showcasing all the techniques that NgModules related pages\ncover, see the
Modules are a great way to organize an application and extend it with capabilities from external libraries.
\nAngular libraries are NgModules, such as FormsModule
, HttpClientModule
, and RouterModule
.\nMany third-party libraries are available as NgModules such as\nMaterial Design,\nIonic, and\nAngularFire2.
NgModules consolidate components, directives, and pipes into\ncohesive blocks of functionality, each focused on a\nfeature area, application business domain, workflow, or common collection of utilities.
\nModules can also add services to the application.\nSuch services might be internally developed, like something you'd develop yourself or come from outside sources, such as the Angular router and HTTP client.
\nModules can be loaded eagerly when the application starts or lazy loaded asynchronously by the router.
\nNgModule metadata does the following:
\nEvery Angular app has at least one module, the root module.\nYou bootstrap that module to launch the application.
\nThe root module is all you need in a simple application with a few components.\nAs the app grows, you refactor the root module into feature modules\nthat represent collections of related functionality.\nYou then import these modules into the root module.
\nThe Angular CLI generates the following basic AppModule
when creating a new app.
At the top are the import statements. The next section is where you configure the @NgModule
by stating what components and directives belong to it (declarations
) as well as which other modules it uses (imports
). For more information on the structure of an @NgModule
, be sure to read Bootstrapping.
You may also be interested in the following:
\n\n\n \n