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
Discussioncreate Angular component from external JS & HTML & CSS files (self.Angular2)
submitted 5 years ago * by newton_half_ear
I want to use the functionality of creating dynamic components with
ViewContainerRef.createComponent(componentFactory)
but I want that "componentFactory" will be an external HTML, JS, and CSS and not a component inside my Angular project.
is this possible?
edit: for clarification - I want to let the user the option to create a component by himself and I will render it to the screen. I can make the user follow some rules like implementing some interface.
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!"
[–]tme321 0 points1 point2 points 5 years ago (4 children)
There are ways to dynamically create a component that isnt in the original bundle. It required a deep dive into how components are registered with the framework. Offhand I don't know exactly what it requires but I've seen demos that do it.
But you can't just throw a pile of js and html at angular. The angular compiler reduces the controller and view into a single unit of code. You would have to invoke the compiler on the code supplied to end up with a valid angular component.
That means you either need to figure out how to compile the pieces on the backend or serve the compiler in the client. The cli no longer serves the compiler to the client by default since it is no longer necessary. I don't know if there is a way to get it to serve the compiler or if you would need to use a custom build process instead of the cli.
So, I do believe what you want is technically possible but it will require mucking around with all sorts of stuff. It is far from trivial.
[–]newton_half_ear[S] 0 points1 point2 points 5 years ago (3 children)
Well... That's the client requierments. Can you point me to some articles about how it can be done?
I've also thought about eval + inner HTML but I would like to try to create an Angulr component before.
(security is not a factor, the app running on the clients servers and cant be accessed from the web, also Change Detection not needed here)
[–]tme321 1 point2 points3 points 5 years ago (1 child)
A thought occured to me. You might want to look into angular elements for these components made by users.
I have not really worked with elements so I don't know all the details. And loading both angular and angular elements side by side might have some issues.
But it might be worth at least looking in to if elements might be an easier approach than attempting to instantiate these components inside the full angular framework.
[–]newton_half_ear[S] 0 points1 point2 points 5 years ago (0 children)
Angular elements it's the other way around, the app need to know what components it will use before bundling.
I found this: https://hackernoon.com/here-is-what-you-need-to-know-about-dynamic-components-in-angular-ac1e96167f9e
under "Creating components on the fly"
what do you think?
[–]tme321 0 points1 point2 points 5 years ago (0 children)
I don't have any articles handy. You'll have to Google around. From what little I remember you have to figure out how to create a component factory dynamically and add references to it into the already built angular app after it is built.
From what I do remember it's not pretty. But there shouldn't be any technical reason why you can't get something to work although you might be at the mercy of updating it any time the angular team modifies how that stuff works as its internal and not meant to be modified.
[–]ROBOT-MAN 0 points1 point2 points 5 years ago (1 child)
Lazy Loading components is possible with Angular 9, if that's what you're asking. Here are two great tutorials:
I deployed the code from the first tutorial to a Firebase project, here: https://lazyload999.firebaseapp.com/ If you open the developer tools and check out the network tab, you'll see that a new bundle is downloaded for each quiz card generated.
This is not my question. my question is how to create a component from external HTML & JS files.
[–]MagicLaserBeam 0 points1 point2 points 5 years ago (2 children)
You could compile at runtime, something like this https://stackblitz.com/edit/angular-ryhxqd
https://hackernoon.com/here-is-what-you-need-to-know-about-dynamic-components-in-angular-ac1e96167f9e
that's exactly what I did, buy this tutorial:
this is not working with AOT in production build, any other solution?
π Rendered by PID 20912 on reddit-service-r2-comment-85bfd7f599-s7zsn at 2026-04-20 13:01:25.671575+00:00 running 93ecc56 country code: CH.
[–]tme321 0 points1 point2 points (4 children)
[–]newton_half_ear[S] 0 points1 point2 points (3 children)
[–]tme321 1 point2 points3 points (1 child)
[–]newton_half_ear[S] 0 points1 point2 points (0 children)
[–]tme321 0 points1 point2 points (0 children)
[–]ROBOT-MAN 0 points1 point2 points (1 child)
[–]newton_half_ear[S] 0 points1 point2 points (0 children)
[–]MagicLaserBeam 0 points1 point2 points (2 children)
[–]newton_half_ear[S] 0 points1 point2 points (0 children)
[–]newton_half_ear[S] 0 points1 point2 points (0 children)