ngUpgraders / ng-forward

The default solution for those that want to write Angular 2.x style code in Angular 1.x
411 stars 36 forks source link

Dynamically Loading / Lazy Loading Components #121

Closed micahlee closed 6 years ago

micahlee commented 8 years ago

I have an angular 1 application that dynamically loads element directives with systemjs to lazily compile and render after the initial application loads and bootstraps. I do this now by capturing the $compileProvider when I create the module, and then I use it later to register directives as they're loaded with system.js so that I can use $compile to render them from within a parent component directive.

Is there a proper way to do something like this with ng-forward? I see in angular 2 there is a DynamicComponentLoader, but I don't know enough about it to know if it's actually relevant to this or if there is an ng-forward equivalent.

Thanks for the hard work! I've been very impressed with how easy it's been to start moving existing angular 1 code over to start getting prepared for angular 2. :+1:

timkindberg commented 8 years ago

So the "proper" way in ng-forward would be however we would have to do it in Angular 2. If you could do the research to find the canonical Angular 2 way of doing this, then we can slot a story that adds the functionality to ng-forward. Since it's clearly possible in angular 1, it's just a matter of putting the correct facade over top of it.

micahlee commented 8 years ago

Sorry for the delay. After a little more reading, it looks like DynamicComponentLoader is the way to go in Angular 2. I'll try to put something together that achieves the goal in angular 1 and 2 as a comparison.

Also, as a side note, I am able to workaround my issue right now by performing the dynamic loading in a angular 1 module that is just an additional named provider for the ngForward components.

timkindberg commented 8 years ago

Awesome, if you could post your example for others looking in the future that would be great!!

heiso commented 8 years ago

Hi there :) @micahlee

Also, as a side note, I am able to workaround my issue right now by performing the dynamic loading in a angular 1 module that is just an additional named provider for the ngForward components.

Is your workaround still relevant ? Should be awesome to look at an example :)

micahlee commented 6 years ago

Closing as no longer relevant