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 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
transform-origin Property in CSSCSSWhat are “holes” in a React component?ReactIntroduction to Angular modules Part 2: NgModules and componentsAngularUse eq() method in jQueryjQueryHow to convert a number rounding to a specified number of decimals in JavaScript?JavaScriptWhat are Identifiers in JavaScript?JavaScript