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

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.

主站蜘蛛池模板: 嘉兴市| 江山市| 民和| 杭锦后旗| 桂林市| 华宁县| 高雄市| 青冈县| 临安市| 资溪县| 平邑县| 庄河市| 双城市| 武乡县| 故城县| 铁岭县| 客服| 苏尼特右旗| 宣恩县| 安徽省| 榆社县| 海阳市| 廊坊市| 香港 | 新邵县| 阿合奇县| 余干县| 垣曲县| 林州市| 桦甸市| 城固县| 安化县| 临潭县| 南阳市| 鄂州市| 始兴县| 延寿县| 开平市| 沙田区| 汝城县| 北京市|