依赖注入:Dependency Injection 简称DI(实现控制反转的手段称为依赖注入)
控制反转:Inversion of Control 简称IOC (依赖的控制权由代码的内部转到代码的外部)
var product = new Product(); createShipment(product);
var product = new MockProduct(); //MockProduct是product的子类
createShipment(product);
@NgModule({ providers: [productService] //等同于providers:[{provide:ProductService,useClass:ProductService}] })
依赖注入的好处:松耦合,可重用,可测性
注入器
constructor(private productService){.....}
提供器
providers: [productService]