I am trying to implement dynamic component. My requirement is, I have three class- LayoutComponent, MenuService and DynamicService. LayoutComponent is used to call the MenuService's method to perform some basic operation, after performing operation, MenuService's method again call to DynamicService's method for creating dynamic component.
Here is my Plunker with the following error which it gives
Unhandled Promise rejection: No provider for ViewContainerRef! ;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With