Angular 注入器层次结构
1. Platform Injector
2. Application Injector
官方文档:If you only specify providers at the top level (typically the root 3. LazyModule Injector
如果同一个服务在多个注入器(Application Injector和LazyModule Injector)被provide,容易导致bug: 在Module类上定义forRoot()静态方法可以避免在不同的注入器注册同一个服务: 4. View Injector在已经提到的3种Injector之下,还有View Injector。
<parent-component> <content-child-component></content-child-component> </parent-component> 即使父组件将Content Child投影(project)到<ng-content>中,Content Child也可以通过DI拿到父组件的实例,实现父组件与Content Child之间的交流。 完整视频https://youtu.be/EoSn8qASqQA (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |