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

Dependency injection

Maybe the first framework on the market that included Inversion of Control (IoC) through Dependency Injection (DI) in the JavaScript world was AngularJS. DI provides a number of benefits, such as easier testability, better code organization and modularization, and simplicity. Although the DI in AngularJS does an amazing job, Angular took this even further. Since Angular is on top of the latest web standards, it uses the syntax of ECMAScript 2016 decorators for annotating the code for using DI. Decorators are quite similar to the decorators in Python or annotations in Java. They allow us to decorate the behavior of a given object, or add metadata to it, using reflection. Since decorators are not yet standardized and supported by major browsers, their usage requires an intermediate transpilation step.

The new DI is much more flexible and feature-rich. It also fixes some of the pitfalls of AngularJS, such as the different APIs; in the first version of the framework, some objects are injected by position (such as the scope, element, attributes, and controller in the link function of the directives) and others, by name (using parameters names in controllers, directives, services, and filters).

We will take a further look at the Angular's dependency injection API in Chapter 6, Dependency Injection in Angular.

主站蜘蛛池模板: 特克斯县| 沁阳市| 太湖县| 阳东县| 襄城县| 竹溪县| 邳州市| 西盟| 广汉市| 大田县| 罗平县| 德令哈市| 依兰县| 澄江县| 报价| 美姑县| 侯马市| 平乐县| 博乐市| 司法| 武汉市| 丹寨县| 临西县| 化德县| 山西省| 黑河市| 肥西县| 万山特区| 瑞金市| 县级市| 保定市| 西贡区| 怀安县| 日土县| 施甸县| 永顺县| 宁国市| 汉沽区| 木里| 沙湾县| 东阿县|