官术网_书友最值得收藏!

  • Expert Angular
  • Mathieu Nayrolles Rajesh Gunasundaram Sridhar Rao
  • 260字
  • 2021-07-15 17:05:28

NgModules

Angular framework has various libraries that are grouped as modules in order to build an application. Angular applications are modular in nature and are constructed by assembling various modules. Modules may have components, services, functions, and/or values. Some modules may have a collection of other modules and are known as library modules.

Angular packages, such as core, common, http, and router that are prefixed with @angular comprise many modules. We import what our application needs from these library modules as follows:

import {Http, Response} from @angular/http'; 

Here, we import Http and Response from the library module, @angular/http. @angular/http refers to a folder in the Angular package. Any module defined to be exported can be imported into another module by referring to the filename of the module.

Note: this import statement was introduced in ES2015 and is used to import objects or function that are exported from other modules or scripts


However, we can also refer to the folder as we referred to @angular/http. This can be achieved by adding an index.ts file to the folder and adding the code to export modules from the folder. This is a best practice suggested by Angular's style guide and is called the barrel technique:

export * from './http'; 

This is the export statement in the index.ts found in @angular/http. The statement means that it exports all the modules in HTTP and that they can be imported to our application wherever needed.

When we write an Angular application, we start by defining an AppComponent (not necessarily with the same name) and exporting it.

主站蜘蛛池模板: 黑龙江省| 曲松县| 徐闻县| 惠安县| 邓州市| 颍上县| 工布江达县| 历史| 普洱| 八宿县| 沅陵县| 隆尧县| 安陆市| 临城县| 晋中市| 吉林市| 郎溪县| 土默特左旗| 丁青县| 绥德县| 堆龙德庆县| 吴堡县| 苍梧县| 正安县| 清涧县| 固阳县| 济源市| 江川县| 安岳县| 岗巴县| 重庆市| 壤塘县| 诸城市| 邢台市| 旬邑县| 漳平市| 固始县| 闸北区| 清涧县| 富锦市| 沧州市|