Anguler2 - Unhandled Promise rejection: No provider for ViewContainerRef! ( In dynamic template )
ViewContainerRef
can only be injected to components or directives, but not to services.
Components and directives get the ViewContainerRef
of the element where they itself are attached. A service isn't attached to any view.
What you can do is to inject ViewContainerRef
and a service to a component and then in the constructor pass the ViewContainerRef
to the service. Every service or component that injects this service can access the ViewContainerRef
it holds.