Angular NgModules and JavaScript Modules

Angular NgModules and JavaScript Modules

The Angular NgModule system is different from and unrelated to the JavaScript (ES2015) module system for managing collections of JavaScript objects. These are two different and complementary module systems. You can use them both to write your apps.

 

In JavaScript each file is a module and all objects defined in the file belong to that module. The module declares some objects to be public by marking them with the export key word. Other JavaScript modules use import statements to access public objects from other modules.

 

import { NgModule }     from ‘@angular/core’;

import { AppComponent } from ‘./app.component’;

 

export class AppModule { }

JavaScript Module System

JavaScript has had modules for a long time. However, they were implemented via libraries, not built into the language.

 

In JavaScript, modules are individual files with JavaScript code in them. To make what’s in them available, you write an export statement, usually after the relevant code, like this:

 

export class AppComponent { … }

 

Then, when you need that file’s code in another file, you import it like this:

 

import { AppComponent } from ‘./app.component’;

 

JavaScript modules help you namespace, preventing accidental global variables.

IT Professionals, Web Developers, Web Programmers, IT students can Apply for the certification course to move ahead in their careers.

Angular 4 Tutorial IndexBack to Angular 4 Tutorial Main Page

Angular NgModules and Components
Angular Entry Components

Get industry recognized certification – Contact us

keyboard_arrow_up