-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
[RC6][REGRESSION][ngUpgrade] Error: Only selectors matching element names are supported #11280
Comments
Please describe more clearly:
|
Current behaviour @Component({
selector: '[alertManagerRow]',
template: `
<td>foo</td>
<td>bar</td>
`
}) Use case: <table>
<thead>
<tr>
<th>1st column</th>
<th>2nd column</th>
</tr>
</thead>
<tbody>
<tr alertManagerRow [number]="777"></tr>
<tr alertManagerRow [number]="333"></tr>
</tbody>
</table> Error: zone.js:461 Unhandled Promise rejection: Only selectors matching element names are supported, got: [alertManagerRow] ; Zone: ; Task: Promise.then ; Value: Error: Only selectors matching element names are supported, got: [alertManagerRow] With RC5 was working perfectly. Expected behaviour Steps to reproduce |
We have the same issue on our project. |
We have the same issue on our project but with SVG attribute (rc.6). The application is working well with rc.5
Everything works fine without the UpgradeAdapter, plunk: http://plnkr.co/edit/w7Tw38KAZOlNCluliKR1?p=preview "Only selectors matching element names are supported" error with UpgradeAdapter, just see console error in this plunk: http://plnkr.co/edit/44uWEp?p=preview The issue is with these lines. In my example, the selector contains square brackets: [label]
Thank you |
@dions00 If I comment the line: throw new Error('Only selectors matching element names are supported, got: ' + selector); It's working again, great! But hope to have an official fix soon. Thanks! |
My understanding is that you can only ngUpgrade element selector based components. I recall seeing this issue where it's explained that attribute selectors will give ownership of the host element to both frameworks: #7026 |
See my comment: #7026 (comment) Here we're not downgrading any |
We have updated to angular 2.0.0 final and the problem described by dions00 in his plunker is still there http://plnkr.co/edit/44uWEp?p=preview . Are we doing something wrong ? Is there any workaround ? |
Like dions00 has pointed out, if only the COMPONENT_SELECTOR regular expression was containing the support of the square brackets in selector, it would work like a charm.
something like this would work |
Looking at the code, this issue seems to have been introduced by this commit
_bootstrapModuleWithZone is now called with a callback which is, according to the comment left in the code, an ugly internal api hack :)
|
This is a blocker for the UI-Router hybrid app adapter past rc.5 |
@vicb - any updates on this? I can't move to latest because of ui-router not being able to. :( |
Trying to use ng-bootstrap also results in this issue. Even though I'm not downgrading any of the ng-bootstrap components, I get this error when trying to bootstrap using ngUpgrade:
To be clear, I'm not using the date picker at all. Indeed, I'm not yet using any ng-boostrap component - merely to include the service. |
this is definitely a blocker for people using the |
@vicb let us know if you need any more details |
It looks like there are two issues going on: 1/ some Angular 1 applications use attribute selectors for their components and it is not possible to update these components to Angular 2 components because of a check in angular/upgrade
2/ some Angular 2 applications use attribute selectors for their components and when they bootstrap the application via angular/upgrade the bootstrap fails because these Angular 2 components fail to pass the same check in angular/upgrade even though they are not being downgraded to Angular 1
These two issues while having similar symptoms are unrelated and need to be resolved separately. I understand that some Angular 1 code might have existing components that use attribute selectors for legacy reasons. What is not clear to me and I'd really like to understand why is there a need for Angular 2 components to use attribute selectors instead of element selectors. Can someone please explain the use-cases where attribute-selectors are absolutely needed? |
|
Hey @IgorMinar thanks for the prompt and thorough response. I've got the second problem you've listed, via ng-bootstrap. I don't have an opinion as to whether attribute selectors are right or wrong. I've just started with angular 2, and it's not a great experience to have a problem with a well established library like ng-bootstrap. Given that examples like this exist in the wild, would it be possible to temporarily relax the check in angular/upgrade and then deprecate attribute selectors for both angular/upgrade and angular/compiler? |
@IgorMinar thanks for looking into this issue. UI-Router is blocked by the latter (import a module with an ng2 component with an attribute selector).
Attribute selectors might be necessary when the tag types are important. Something like
Will that restriction be added and enforced in some future version of angular? In UI-Router, we don't absolutely need |
@amcdnl In many cases it is an anti-pattern. We are analyzing the use-cases we can find to see if all of them are anti-patterns. DOM places some restrictions on nesting of elements, but in most cases there is a solution that doesn't require attribute selectors. Your example with the title tag is not ideal because title is a non-visual element so you can't add a tooltip to it. When it comes to tooltip itself, if you implement it as a component you will not be able to place it on another component which is likely not what you want, so if you want a tooltip that is usable in most scenarios, you should implement it as a directive. Take a look at this implementation: https://github.com/angular/material2/blob/master/src/lib/tooltip/tooltip.ts @studds I've had a chat with @pkozlowski-opensource from ng-bootstrap about their use of attribute selectors. we'll resolve the ng-bootstrap issue one way or another. @christopherthielen I'd strongly suggest that you switch over to element selectors for ui-view. |
I definitively agree with @IgorMinar that a tooltip shouldn't be a component but rather a directive. This is what we do in ng-bootstrap as well: https://github.com/ng-bootstrap/ng-bootstrap/blob/40bde5e09d292cc714e41b1783c5bcb8e1cbd067/src/tooltip/tooltip.ts#L39 As Igor mentioned I'm going to have a look at other table-related use-cases tomorrow (tables seem to be the most restrictive when it comes to which elements you can stick between table / tbody / tr) to see what happens with other projects in the wild.
If we determine that attribute selector for components should be banned then we are going to change ng-bootstrap impl within a day or 2. |
Sorry, I misunderstood that this was restricted to components only. Please disregard my comment about the title tags. However, you can see how I use attribute selectors on my charting framework to build svg chart components - https://github.com/swimlane/ng2d3/blob/master/src/bar-chart/bar-horizontal-stacked.component.ts#L47 @pkozlowski-opensource regarding:
SVG's are even more restrictive. All in all, I think either way it should be slowly deprecated. Anyone upgrading their app this will just be another extra hoop for them to jump through. |
Regardless if it is antipattern or not it should not be |
…re not part of upgrade fixes angular#11280
…re not part of upgrade fixes angular#11280
@IgorMinar for svg you cannot use any element name that you want, you often have to use |
Even if its an anti pattern cant it be just a warning log rather than hard Thanks & regards, On 22 Sep 2016 11:17, "Olivier Combe" notifications@github.com wrote:
|
I think @dions00 's comment demonstrate very well a use-case where attribute-selectors are absolutely needed. Like it had been said SVG must respect very strong constraints in term of hierarchy and the only way to perform data binding on a svg:rect is to use an attribute selector. If someone knows another way, I woud be happy to know it. |
@mhevery |
the fix is in 2.0.1 |
Thank you it works well Thanks & regards, On 24 Sep 2016 00:02, "Igor Minar" notifications@github.com wrote:
|
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. |
I'm submitting a ... (check one with "x")
Current behavior
With RC5 it's working fine.
With RC6: Error: Only selectors matching element names are supported, got: [alertManagerRow].
Reproduction of the problem
http://plnkr.co/edit/PvVWdDG5RfN7ZzVn0gUu?p=preview
Please provide a way to implement it, as you can see in the plunkr, it cannot be used as a non-attribute definition.
Please tell us about your environment:
The text was updated successfully, but these errors were encountered: