(六)依赖注入基础
2017-07-18 本文已影响0人
马丁路德东
依赖注入是提高组件可重用性的主要方法,解决组件之间的松耦合(也叫什么控制反转)概念性问题。
最基础的依赖注入
1.基础服务的写法

2.在模板上引入他

3.在组建的控制器的构造函数里接受服务,然后再HTML上展示就行

(二)进阶版注入依赖------声明在组件里。
1.写服务时,可以借助其他服务

2.组件中注入服务

我们一般将服务声明在模块层,除非此服务必须对其他组件不可见是才将他声明在组件中
(三)服务之间的相互注入。
1.服务书写和以前一样
注意只有服务有@Injectable装饰器,服务才能允许注入其他服务。

2.服务接受语法,和以前一样。

3.在模块中声明他
