-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
NG8011: Node matches the X slot of the Y component, but will not be projected into the specific slot because the surrounding @if has more than one node at its root. #54077
Comments
Whitespaces count as text nodes if your application is no configured with |
I have a particular need for |
You can remove the whitespace inside the |
The warning mentions that the component has
|
It does not, however, suggest a way to fix the problem while maintaining |
@Kerrick can you issue be resolved by using |
I have, same problem, it was working fine with old *ngFor in my scenario. |
…jection - provide an example of using ng-container with ngProjectAs - add more information about whitespaces Related to angular#54077
For additional context, see Caveat 2 mentioned in this commit which is related to #52277. |
The suggested workaround form the warning message work well for me. <mat-form-field subscriptSizing="dynamic">
<mat-label>Phone Number</mat-label>
<input
matInput
[formControl]="form.controls.phoneNumber"
required
type="tel"
/>
<ng-container ngProjectAs="mat-error"> <!-- Or for attribut <ng-container matError> -->
@if (form.controls.phoneNumber.hasError('isPhoneNumber')) {
<mat-error>Must be a valid U.S. phone number</mat-error>
}
</ng-container>
</mat-form-field> |
So is there a way to use Edit: Read the Caveat 2 in the commit. Guess this will stay and we'll have to live with it... |
Which @angular/* package(s) are the source of the bug?
compiler
Is this a regression?
Yes
Description
I have the following code which causes a warning during compilation, but the warning suggests fixes that don't apply to the code in question.
This caused the following compiler warning, followed by some suggestions to fix it.
The bug here is that there is not more than one node at the root of the @if. Suggestion 1 is basically already in-place, suggestion 2 is impossible, and section 3 is already in-place.
Note that this is not a duplicate of #53477, because #53477 is a case where the content does need to be split/wrapped.
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run
ng version
)Anything else?
This happens in many other similar (one root node inside the
@if
) instances--not always MatFormField, even--across my application.The text was updated successfully, but these errors were encountered: