Yogesh Chauhan's Blog

Introduction to Angular modules Part 2: NgModules and components

in Angular on May 9, 2020

If you haven't read it yet, here is the Part 1 Link:

Introduction To Angular Modules Part 1: NgModule Metadata

Introduction to Angular modules: Part 2

NgModules and components

NgModules provide a compilation context for their components.

A root NgModule always has a root component that is created during bootstrap.

Any NgModule can include any number of additional components, which can be loaded through the router or created through the template.

The components that belong to an NgModule share a compilation context.

A component and its template
A component and its template

A component and its template together define a view.

A component can contain a view hierarchy, which allows you to define arbitrarily complex areas of the screen that can be created, modified, and destroyed as a unit.

A view hierarchy can mix views defined in components that belong to different NgModules. This is often the case, especially for UI libraries.

A view hierarchy
A view hierarchy

When you create a component, it's associated directly with a single view, called the host view.

The host view can be the root of a view hierarchy, which can contain embedded views, which are in turn the host views of other components.

Those components can be in the same NgModule, or can be imported from other NgModules.

Views in the tree can be nested to any depth.

Note: The hierarchical structure of views is a key factor in the way Angular detects and responds to changes in the DOM and app data.


Introduction To Angular Modules Part 3: NgModules Vs JavaScript Modules And Angular Libraries

Credit: Angular.io

Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
The 7 Security Objectives of Any Organization for IT and Network SecurityMiscellaneousValues and Types Basics in JavaScriptJavaScriptReview an intentionally vulnerable plugin in WordPressWordPressWhat is Object Mutability in JavaScript?JavaScriptFETCH clause in PostgreSQLPostgresThe Lending Club Analysis using Logistic Regression and Random Forest in RStudioMiscellaneous