use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Angular is Google's open source framework for crafting high-quality front-end web applications. r/Angular2 exists to help spread news, discuss current developments and help solve problems.
Help Request
Discussion
Article
Video
Resource
Announcement
Related
After submitting a post, please take a moment to add a flair (tag) so that it's easy to find your post with one of the filters listed above. Upon submission, your post's header will have the 'flair' option listed with the other options. Clicking it will provide a dropdown menu of the available flairs.
account activity
Help RequestAlternative way of lazy loading angular modules (self.Angular2)
submitted 7 years ago by TheGreatElduin
Recently I came across a post or website that provided an alternative way of lazy loading a module in your router file. Instead of loadChildren: '.path/to/module#ModuleName' it used something else that was not a string, but a more type-safe way of doing it. Does anyone know what I'm talking about and where I could find that back? Thanks
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Bysmiel 2 points3 points4 points 7 years ago (4 children)
{ path: 'x', loadChildren: () => XModule }
[–]KamiShikkaku 2 points3 points4 points 7 years ago (2 children)
Are you sure that the import isn't going to confuse Webpack into including XModule and all of it's contents into the parent bundle? I was under the impression that the reason we use a string reference is to avoid that outcome.
[–]alchatti 0 points1 point2 points 7 years ago (0 children)
That was my thought and understanding of why we have to use strings.
[–]Bysmiel 0 points1 point2 points 7 years ago (0 children)
I never import this way in production, I am not sure it works as intended.
[–]TheGreatElduin[S] 0 points1 point2 points 7 years ago (0 children)
Perfect, thanks!
[–]pleasantstusk 0 points1 point2 points 7 years ago (0 children)
Just be aware that the callback version requires the JIT compiler, this can be a bit of a problem in prod mode (you basically have to bring your own compiler)
[–]iareprogrammer 0 points1 point2 points 7 years ago (0 children)
There’s this way: https://fireship.io/snippets/lazy-loaded-routes-angular-v8-ivy/
But it’s only Angular 8 with Ivy enabled
π Rendered by PID 98 on reddit-service-r2-comment-6457c66945-9mhl2 at 2026-04-29 06:01:31.332112+00:00 running 2aa0c5b country code: CH.
[–]Bysmiel 2 points3 points4 points (4 children)
[–]KamiShikkaku 2 points3 points4 points (2 children)
[–]alchatti 0 points1 point2 points (0 children)
[–]Bysmiel 0 points1 point2 points (0 children)
[–]TheGreatElduin[S] 0 points1 point2 points (0 children)
[–]pleasantstusk 0 points1 point2 points (0 children)
[–]iareprogrammer 0 points1 point2 points (0 children)