Component as Injectable?

前端 未结 1 1232
轻奢々
轻奢々 2020-12-10 14:07

I am trying to build my own Modal component, that I would be able to reuse throughout my Angular2 Apps. I am considering different approaches, and I am wondering if it is po

相关标签:
1条回答
  • 2020-12-10 14:43

    A component is injectable by default @Component() (or @Directive()) includes @Injectable().

    Don't expect to get a specific instance of a component injected. This works for example with constructor(@Host() private parentComponent) where DI lookup is limited to parent injectors up to the injector of the host element.

    Normally for your use case DynamicComponentLoader is used which only accepts the type of a component, not an instance. Dependency injection would just create an instance of the components class but not for example the associated view.

    0 讨论(0)
提交回复
热议问题