No injector for custom defined data type的解决办法

No injector for custom defined data type的解决办法

“message”: "Can’t resolve all parameters for AppComponent in c:/Code/SPA/mystore/src/app/app.component.ts
No injector for custom defined data type的解决办法

‘DebugConfig’ only refers to a type, but is being used as a value here.

解决办法

在app module里定义一个abstract class:

No injector for custom defined data type的解决办法

在NgModule的providers里定义这个injectable objects:

No injector for custom defined data type的解决办法

此时在Component里就可以注入DebugConfig了:

No injector for custom defined data type的解决办法

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
No injector for custom defined data type的解决办法