I'm looking for a substitute for deprecated ComponentFactoryResolver and ComponentFactory classes in Angular 13. The official documentation as well as another question here on SO suggest using ViewContainerRef, but my application instantiates Angular components in a service, outside of the DOM. There is no ViewContainerRef available.
The instantiated components are not to be shown to the user. They are used to generate in-memory SVGs that are then rasterized and used for further purposes.
This is what I've used until now in my service:
let factoryHistogram = this.resolver.resolveComponentFactory(HistogramComponent);
let newNode = document.createElement('div');
this.histogramComponent = factoryHistogram.create(this.injector, [], newNode);
this.app.attachView(this.histogramComponent.hostView);
How can I achieve the same in Angular 13?
The fact that it is no longer possible to create a component without also inserting it into DOM has been reported as a possible regression over there:
https://github.com/angular/angular/issues/45263
Hopefully the core team will be able to figure out a way to keep supporting this use case.
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