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

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.

主站蜘蛛池模板: 如东县| 天津市| 泌阳县| 澄江县| 广东省| 洪江市| 上高县| 敖汉旗| 雅江县| 都江堰市| 宁南县| 云阳县| 林州市| 湖南省| 德州市| 抚顺县| 昔阳县| 桃园市| 金寨县| 红河县| 荣成市| 临澧县| 独山县| 兴化市| 九龙坡区| 河东区| 浮山县| 望江县| 淮滨县| 汝南县| 荆门市| 莱州市| 韶山市| 马山县| 饶平县| 丹阳市| 武穴市| 克山县| 晋州市| 南宫市| 巨鹿县|