How to access _factories property from ComponentFactoryResolver in Angular9 which was available in Angular7?
Asked Answered
O

1

3

I used ComponentFactoryResolver to access all the entry component factories and then add routes of those components dynamically in Angular 7.

constructor(private componentFactoryResolver: ComponentFactoryResolver) {
}

var factories = this.componentFactoryResolver['_factories']

let route: Route = {
                path: MyPath,
                component: factories[0].factory[1].componentType
            };

this.router.resetConfig(config);

I updated my project to Angular 9 and now _factories are not available in ComponentFactoryResolver.

var factories = this.componentFactoryResolver['_factories']

It returns undefined in Angular 9. It will be great help if someone can suggest some way to access all the entry component list on the go. The problem is that I have don't any information available about the entry components from which I may recompile the components through Compiler and add their routes.

Oilskin answered 10/5, 2020 at 5:49 Comment(0)
S
0

I think a simpler approach might be to import the component and use it directly in place of factories[0].factory[1].componentType. Example:

import { MyComponent } from '@app/my.component';

constructor(private componentFactoryResolver: ComponentFactoryResolver) {
}

let route: Route = {
                path: MyPath,
                component: MyComponent
            };

this.router.resetConfig(config);
Scruff answered 18/11, 2020 at 3:1 Comment(1)
I want keep this routing dynamic. Let's say I don't have components directly imported to my service. That is why I was accessing it from entry component factories on the fly. But in Angular 9+, these factories aren't available.Oilskin

© 2022 - 2024 — McMap. All rights reserved.