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

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.

主站蜘蛛池模板: 天水市| 石狮市| 台中县| 玛沁县| 巨鹿县| 连山| 定州市| 太谷县| 扎兰屯市| 小金县| 江永县| 株洲市| 新民市| 阿拉善左旗| 延川县| 遂溪县| 新平| 寿宁县| 左云县| 禹州市| 盐池县| 乐平市| 九寨沟县| 耿马| 松桃| 黄浦区| 桂林市| 日喀则市| 开江县| 子洲县| 轮台县| 南安市| 呈贡县| 灵寿县| 江安县| 紫阳县| 昌邑市| 阳信县| 青铜峡市| 涞源县| 衡阳市|