{"id":71730,"date":"2020-01-10T16:24:42","date_gmt":"2020-01-10T10:54:42","guid":{"rendered":"https:\/\/www.vskills.in\/certification\/tutorial\/?p=71730"},"modified":"2024-04-12T14:22:40","modified_gmt":"2024-04-12T08:52:40","slug":"ngmodule-api","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/","title":{"rendered":"NgModule API"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.vskills.in\/certification\/tutorial\/angular-7-developer-tutorials\/\" target=\"_blank\" rel=\"noreferrer noopener\">Go back to Tutorial<\/a><\/p>\n\n\n<p>At a high level, NgModules are a way to organize Angular apps and they accomplish this through the metadata in the @NgModule decorator. The metadata falls into three categories:<\/p>\n<ul>\n<li>Static: Compiler configuration which tells the compiler about directive selectors and where in templates the directives should be applied through selector matching. This is configured via the declarations array.<\/li>\n<li>Runtime: Injector configuration via the providers array.<\/li>\n<li>Composability\/Grouping: Bringing NgModules together and making them available via the imports and exports arrays.<\/li>\n<\/ul>\n<p>@NgModule({<\/p>\n<p>\/\/ Static, that is compiler configuration<\/p>\n<p>declarations: [], \/\/ Configure the selectors<\/p>\n<p>entryComponents: [], \/\/ Generate the host factory<\/p>\n<p>\/\/ Runtime, or injector configuration<\/p>\n<p>providers: [], \/\/ Runtime injector configuration<\/p>\n<p>\/\/ Composability \/ Grouping<\/p>\n<p>imports: [], \/\/ composing NgModules together<\/p>\n<p>exports: [] \/\/ making NgModules available to other parts of the app<\/p>\n<p>})<\/p>\n<p>@NgModule metadata<\/p>\n<p>The following table summarizes the @NgModule metadata properties.<\/p>\n<p>&nbsp;<\/p>\n<table>\n<thead>\n<tr>\n<td width=\"140\"><strong>Property <\/strong><\/td>\n<td width=\"498\"><strong>Description<\/strong><\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td width=\"140\">declarations<\/td>\n<td width=\"498\">A list of declarable classes, (components, directives, and pipes) that belong to this module.<p><\/p>\n<p>\u00fc&nbsp; When compiling a template, you need to determine a set of selectors which should be used for triggering their corresponding directives.<\/p>\n<p>\u00fc&nbsp; The template is compiled within the context of an NgModule\u2014the NgModule within which the template&#8217;s component is declared\u2014which determines the set of selectors using the following rules:<\/p>\n<p>\u00fc&nbsp; All selectors of directives listed in `declarations`.<\/p>\n<p>\u00fc&nbsp; All selectors of directives exported from imported NgModules.<\/p>\n<p>Components, directives, and pipes must belong to exactly one module. The compiler emits an error if you try to declare the same class in more than one module.<\/p>\n<p>Don&#8217;t re-declare a class imported from another module.<\/p><\/td>\n<\/tr>\n<tr>\n<td width=\"140\">providers<\/td>\n<td width=\"498\">A list of dependency-injection providers.<p><\/p>\n<p>Angular registers these providers with the NgModule&#8217;s injector. If it is the NgModule used for bootstrapping then it is the root injector.<\/p>\n<p>These services become available for injection into any component, directive, pipe or service which is a child of this injector.<\/p>\n<p>A lazy-loaded module has its own injector which is typically a child of the application root injector.<\/p>\n<p>Lazy-loaded services are scoped to the lazy module&#8217;s injector. If a lazy-loaded module also provides the UserService, any component created within that module&#8217;s context (such as by router navigation) gets the local instance of the service, not the instance in the root application injector.<\/p>\n<p>Components in external modules continue to receive the instance provided by their injectors.<\/p><\/td>\n<\/tr>\n<tr>\n<td width=\"140\">imports<\/td>\n<td width=\"498\">A list of modules which should be folded into this module. Folded means it is as if all the imported NgModule&#8217;s exported properties were declared here.<p><\/p>\n<p>Specifically, it is as if the list of modules whose exported components, directives, or pipes are referenced by the component templates were declared in this module.<\/p>\n<p>A component template can reference another component, directive, or pipe when the reference is declared in this module or if the imported module has exported it. For example, a component can use the NgIf and NgFor directives only if the module has imported the Angular CommonModule (perhaps indirectly by importing BrowserModule).<\/p>\n<p>You can import many standard directives from the CommonModule but some familiar directives belong to other modules. For example, you can use [(ngModel)] only after importing the Angular FormsModule.<\/p><\/td>\n<\/tr>\n<tr>\n<td width=\"140\">exports<\/td>\n<td width=\"498\">A list of declarations\u2014component, directive, and pipe classes\u2014that an importing module can use.<p><\/p>\n<p>Exported declarations are the module&#8217;s public API. A component in another module can use this module&#8217;s UserComponent if it imports this module and this module exports UserComponent.<\/p>\n<p>Declarations are private by default. If this module does not export UserComponent, then only the components within this module can use UserComponent.<\/p>\n<p>Importing a module does not automatically re-export the imported module&#8217;s imports. Module &#8216;B&#8217; can&#8217;t use ngIf just because it imported module &#8216;A&#8217; which imported CommonModule. Module &#8216;B&#8217; must import CommonModule itself.<\/p>\n<p>A module can list another module among its exports, in which case all of that module&#8217;s public components, directives, and pipes are exported.<\/p>\n<p>Re-export makes module transitivity explicit. If Module &#8216;A&#8217; re-exports CommonModule and Module &#8216;B&#8217; imports Module &#8216;A&#8217;, Module &#8216;B&#8217; components can use ngIf even though &#8216;B&#8217; itself didn&#8217;t import CommonModule.<\/p><\/td>\n<\/tr>\n<tr>\n<td width=\"140\">bootstrap<\/td>\n<td width=\"498\">A list of components that are automatically bootstrapped.<p><\/p>\n<p>Usually there&#8217;s only one component in this list, the root component of the application.<\/p>\n<p>Angular can launch with multiple bootstrap components, each with its own location in the host web page.<\/p>\n<p>A bootstrap component is automatically added to entryComponents.<\/p><\/td>\n<\/tr>\n<tr>\n<td width=\"140\">entryComponents<\/td>\n<td width=\"498\">A list of components that can be dynamically loaded into the view.<p><\/p>\n<p>By default, an Angular app always has at least one entry component, the root component, AppComponent. Its purpose is to serve as a point of entry into the app, that is, you bootstrap it to launch the app.<\/p>\n<p>Routed components are also entry components because they need to be loaded dynamically. The router creates them and drops them into the DOM near a &lt;router-outlet&gt;.<\/p>\n<p>While the bootstrapped and routed components are entry components, you don&#8217;t have to add them to a module&#8217;s entryComponents list, as they are added implicitly.<\/p>\n<p>Angular automatically adds components in the module&#8217;s bootstrap and route definitions into the entryComponents list.<\/p>\n<p>That leaves only components bootstrapped using one of the imperative techniques, such as ViewComponentRef.createComponent() as undiscoverable.<\/p>\n<p>Dynamic component loading is not common in most apps beyond the router. If you need to dynamically load components, you must add these components to the entryComponents list yourself.<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\n\n<p><a href=\"https:\/\/www.vskills.in\/certification\/tutorial\/angular-7-developer-tutorials\/\" target=\"_blank\" rel=\"noreferrer noopener\">Go back to Tutorial<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go back to Tutorial At a high level, NgModules are a way to organize Angular apps and they accomplish this through the metadata in the @NgModule decorator. The metadata falls into three categories: Static: Compiler configuration which tells the compiler about directive selectors and where in templates the directives should be applied through selector matching&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[8294],"tags":[8339],"class_list":["post-71730","page","type-page","status-publish","hentry","category-angular-7","tag-ngmodule-api"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>NgModule API - Tutorial<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"NgModule API - Tutorial\" \/>\n<meta property=\"og:description\" content=\"Go back to Tutorial At a high level, NgModules are a way to organize Angular apps and they accomplish this through the metadata in the @NgModule decorator. The metadata falls into three categories: Static: Compiler configuration which tells the compiler about directive selectors and where in templates the directives should be applied through selector matching....\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T08:52:40+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/\",\"name\":\"NgModule API - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2020-01-10T10:54:42+00:00\",\"dateModified\":\"2024-04-12T08:52:40+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"NgModule API\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"NgModule API - Tutorial","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/","og_locale":"en_US","og_type":"article","og_title":"NgModule API - Tutorial","og_description":"Go back to Tutorial At a high level, NgModules are a way to organize Angular apps and they accomplish this through the metadata in the @NgModule decorator. The metadata falls into three categories: Static: Compiler configuration which tells the compiler about directive selectors and where in templates the directives should be applied through selector matching....","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-04-12T08:52:40+00:00","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/","name":"NgModule API - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2020-01-10T10:54:42+00:00","dateModified":"2024-04-12T08:52:40+00:00","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/ngmodule-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"NgModule API"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/71730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=71730"}],"version-history":[{"count":4,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/71730\/revisions"}],"predecessor-version":[{"id":87867,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/71730\/revisions\/87867"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=71730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=71730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=71730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}