Import modules in Angular2

Understanding, Node js uses the CommonJS module template, and in the CommonJS pattern, we use require () to import the Node module.

In Angular 2 development, we use @ angular / core, @ angular / common, etc. node.

My question is:

Why do we use "import {} from" @ angular / core "[which is the syntax of the ES6 module] instead of the commonJS syntax require () to access the Node modules in angular2 files.

+4
source share
1 answer

The reason for this is because Angular2 is being written in TypeScript.

TypeScript ES2015 ES2015. ES2015 {} .

TypeScript (tsc). , TypeScript, EcmaScript tsconfig.json

  • ES5 , TypeScript import {} from require() .
  • ES6, , , ES2015. , ES6 babel, ES6 ES5 System.js ES6 .

+4
source

Source: https://habr.com/ru/post/1661026/


All Articles