Angular 2 injector hierarchy and NgModule

前端 未结 2 1416
刺人心
刺人心 2021-01-18 12:15

I wonder how NgModule actually affects Angular 2 injector hierarchy.

What does the hierarchy look like in an app with nested modules? Does it create a n

2条回答
  •  伪装坚强ぢ
    2021-01-18 12:58

    You should be able to investigate providers using ng.probe($0) in the browser console. See also https://stackoverflow.com/a/35233711/217408.

    You can load modules with MyModule.forRoot() (see also https://angular.io/docs/ts/latest/guide/ngmodule.html#!#providers) to get providers added at the root level.

    If you provide it in a module, then it's available to the components in this module. I haven't seen it mentioned that a module introduces a child injector explicitly but to me this looks like it has to be the case.

提交回复
热议问题