New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: components without a selector #1662
Comments
Someone needs to define what kind of element the router should create for this component. Right now, we are using the |
This is also something that makes sense for Components you always want to open dynamically (such as overlays). It would be totally reasonable to, in the absence of a selector, just use a |
Wait, so I agree with @jelbourn; a div would suffice as a default. |
@btford yes. |
I don't think this behavior is bad, but Can we use a |
👍 for using |
How about automatically kebab-casing the class name and making it a selector if one is not specified explicitly? Example:
This would allow us to make |
@yjbanov I might be missing something, but does that work with minification? |
@PascalPrecht For production the name could be extracted ahead-of-time via a build step prior to minification and left intact even if the class name is obfuscated. During development you generally do not minify the code and therefore the name can be extracted dynamically at runtime without a build step. |
I did not know that selector is required nor is that apparent in documentation. It has always worked for me without a selector ... no objection from A2 at all. I argue that the selector should remain optional. I omit the selector because it serves no obvious purpose and sends the wrong message. When I specify a selector, I'm implying that Angular should look for a matching target in the parent. That's just not the case with routing. Nor is it the case if I should decide to deploy the component dynamically. I hadn't given much thought to what element is created for the component. I assumed that the result of the template compilation was just dropped into a
If I really cared about creating a wrapper element, I don't need the selector to do that. I just write:
I'm clearly missing your point @yjbanov. And, FWIW, creating an element called |
@wardbell: I merely suggested a method for getting an element name automatically if the developer hasn't specified a selector. Whether we should do that is a separate question. Having to deal with extra wrappers is a valid concern. I like your reasoning that |
We are on the same page ;-) |
@wardbell I 100% agree with you, I suspected it to work like that as well.
Why is it necessary to create a |
@wardbell: Thought of one problem for making selectors not appear in the DOM when instantiated dynamically: it makes introspection harder. If I wanted to find some component on the page in the browser's dev tools I'd first look at element names. If element names are sometimes missing it makes this method of looking for components unreliable. IOW, I'd be querying this same selector in my mind after the component is instantiated, so one could argue that the selector and component element should exist in tandem. The same could apply to tests. If a test is trying to verify that a component appears on the page, it would be very easy to query the same selector. @kasperpeulen: I agree, any automatic wrapper feels random. That's actually what makes the current approach of requiring a selector more consistent: you always get a wrapper irrespective of the method you used to instantiate the component, and the wrapper is always named after the selector*. * one little wart in using the selector as a basis for the element name is that not all selectors can be reverse-engineered into a decent element name. I'm curious what happens today if the selector is |
@yjbanov I agree that introspection is a challenge until the developer of the component offers help. The dev can do that in all kinds of ways with identifying markup in the template itself. Unfortunately, programmatic introspection is only marginally improved by having an element type other than OTOH, if I _do_ know the component I'm looking for, it isn't hard at all ... with or without a known element. I just ask for Also I've never had a problem finding the routed component element as a human probing in the browser tools. It's right there, next to |
If there's always the same tag corresponding to a component then you don't need an Angular-specific mechanism to find it. You just |
Yes, using a selector, to not select something, but to create something seems off. For example I have this component I route to:
I guess not a good idea, to use here the 'div[*ngIf="ready"]` as selector instead |
This is obsolete, and no longer relevant / actionable. To keep our issues clean, we are aggressively closing them. The new router makes this obsolete. |
Please have a look at this issue in router Error: The selector “ng-component” did not match any elements error |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
With the router, it's now possible to have components that are instantiated without needing a selector. However, a call to
compiler.compileInHost
with a component without aselector
in theComponent
annotation throws:I think this is a reasonable case to support.
Related: #2336
The text was updated successfully, but these errors were encountered: