Then, in your directive, you’d inject the ActivatedRoute and the ViewContainerRef and based on your logic, you’d render one component from the array(meaning that you’d also inject DYNAMIC_HEADER_INJECTOR).
I think there is a way to mitigate this issue, but this implies more work from the developer.
If we don’t want to include the component in the main bundle, we can put it in its module and in the directive, based on some conditions, you can load the module on demand by using import(path/to/module).then() and injecting the compiler.
Hi!
I’d follow this approach:
Then, in your directive, you’d inject the ActivatedRoute and the ViewContainerRef and based on your logic, you’d render one component from the array(meaning that you’d also inject DYNAMIC_HEADER_INJECTOR).
Hi :)
Back to topic:
I haven't thought about doing this with injection tokens, lets play it out:
but wouldn't it be then like in the
1st solution
?The components would have to be registered and imported to the AppModule which ends-up raising the initial load of your app
Thats why I wanted to have it loaded only where it really needed to be (and not in the AppModule in my case)
or did I misunderstood your idea?
No, you’re right.
I think there is a way to mitigate this issue, but this implies more work from the developer.
If we don’t want to include the component in the main bundle, we can put it in its module and in the directive, based on some conditions, you can load the module on demand by using import(path/to/module).then() and injecting the compiler.
Yeah like you wrote, another way would be to lazy-load the components of it, there are some helper libaries for this.
I also have one 😁
Lazy Loaded Components - #4 NPM-Package
negue ・ Dec 25 ・ 2 min read
Thanks for sharing!
I’m skeptical about libraries, but I do like to explore them!