Description
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
Currently when I am creating component dynamically, using ViewContainerRef.createComponent()
(or same works for createComponent
function) i have no option how to add/attach directive to newly created component.
I case that i have list of dynamic components (various components) rendered, all implements same interface it would be awesome to have option to dynamically add/attach Directive
to host element of component.
This would add ability to creator of dynamic component to manage which directives are attached to which dynamic component instance.
Proposed solution
Extend options for ViewContainerRef.createComponent()
(also for createComponent
function) with array of "Type" which would create also instances of specified directives on component host with all life cycle stuff.
Let say createComponent<C>(componentType: Type<C>, options?: { index?: number; injector?: Injector; ngModuleRef?: NgModuleRef<unknown>; environmentInjector?: EnvironmentInjector | NgModuleRef<unknown>; projectableNodes?: Node[][]; directives?: Type<unknown>[]; }): ComponentRef<C>
Alternatives considered
Or some other way how to attach directive to dynamic component dynamically.