5 lines
11 KiB
JSON
5 lines
11 KiB
JSON
|
{
|
||
|
"id": "guide/architecture-modules",
|
||
|
"title": "Introduction to modules",
|
||
|
"contents": "\n\n\n<div class=\"github-links\">\n <a href=\"https://github.com/angular/angular/edit/master/aio/content/guide/architecture-modules.md?message=docs%3A%20describe%20your%20change...\" aria-label=\"Suggest Edits\" title=\"Suggest Edits\"><i class=\"material-icons\" aria-hidden=\"true\" role=\"img\">mode_edit</i></a>\n</div>\n\n\n<div class=\"content\">\n <h1 id=\"introduction-to-modules\">Introduction to modules<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"guide/architecture-modules#introduction-to-modules\"><i class=\"material-icons\">link</i></a></h1>\n<p>Angular apps are modular and Angular has its own modularity system called <em>NgModules</em>.\nNgModules are containers for a cohesive block of code dedicated to an application domain, a workflow, or a closely related set of capabilities. They can contain components, service providers, and other code files whose scope is defined by the containing NgModule. They can import functionality that is exported from other NgModules, and export selected functionality for use by other NgModules.</p>\n<p>Every Angular app has at least one NgModule class, <a href=\"guide/bootstrapping\">the <em>root module</em></a>, which is conventionally named <code>AppModule</code> and resides in a file named <code>app.module.ts</code>. You launch your app by <em>bootstrapping</em> the root NgModule.</p>\n<p>While a small application might have only one NgModule, most apps have many more <em>feature modules</em>. The <em>root</em> NgModule for an app is so named because it can include child NgModules in a hierarchy of any depth.</p>\n<h2 id=\"ngmodule-metadata\">NgModule metadata<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"guide/architecture-modules#ngmodule-metadata\"><i class=\"material-icons\">link</i></a></h2>\n<p>An NgModule is defined by a class decorated with <code>@<a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a>()</code>. The <code>@<a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a>()</code> decorator is a function that takes a single metadata object, whose properties describe the module. The most important properties are as follows.</p>\n<ul>\n<li>\n<p><code>declarations</code>: The <a href=\"guide/architecture-components\">components</a>, <em>directives</em>, and <em>pipes</em> that belong to this NgModule.</p>\n</li>\n<li>\n<p><code>exports</code>: The subset of declarations that should be visible and usable in the <em>component templates</em> of other NgModules.</p>\n</li>\n<li>\n<p><code>imports</code>: Other modules whose exported classes are needed by component templates declared in <em>this</em> NgModule.</p>\n</li>\n<li>\n<p><code>providers</code>: Creators of <a href=\"guide/architecture-services\">services</a> that this NgModule contributes to the global collection of services; they become accessible in all parts of the app. (You can also specify providers at the component level.)</p>\n</li>\n<li>\n<p><code>bootstrap</code>: The main application view, called the <em>root component</em>, which hosts all other app views. Only the <em>root NgModule</em> should set the <code>bootstrap</code> property.</p>\n</li>\n</ul>\n<p>Here's a simple root NgModule definition.</p>\n<code-example path=\"architecture/src/app/mini-app.ts\" region=\"module\" header=\"src/app/app.module.ts\">\nimport { <a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a> } from '@angular/core';\nimport { <a href=\"api/platform-browser/BrowserModule\" class=\"code-anchor\">BrowserModule</a> } from '@angular/platform-browser';\n@<a href=\"api/core/NgModule\" class=\"code-anchor\">NgModule</a>({\n imports: [ <a href=\"api/platform-browser/BrowserModule\" class=\"code-anchor\">BrowserModule</a> ],\n providers: [ Logger ],\n declarations: [ AppComponent ],\n exports: [ AppComponent ],\n bootstrap: [ AppComponent ]\n})\nexport class AppModule { }\n\n</code-example>\n<div class=\"alert is-helpful\">\n<p> <code>AppComponent</code> is included in the <code>exports</c
|
||
|
}
|