Skip to content

Angular 17 @empty block not working in nested propagated component #53570

Closed

Description

@WarGreyGon

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

When I try to display some HTML within an @empty block is not rendering anything whereas if I am using a @if approach is working fine.

Bellow snippet belongs to a nested HTML propagated using Angular projections (the main attribute is a projection area)

	<plc-box main *ngrxLet="games$ as games">
		@for (game of games; track game._id) {
		<plc-game-row main [game]="game"></plc-game-row>
		} @empty {                               <!-- <=== This line FAILS-->
		<!-- } @if(games.length === 0) { -->     <!-- <=== This line WORKS-->
		<ng-container main>
			<plc-icon [name]="'landscape'" ></plc-icon>
			<plc-label class="plc-search-game__no-record-label">
				{{ 'pages.search-game.no-results' | translate }}
			</plc-label>
		</ng-container>
		}
	</plc-box>

Same code outside of a propagation based component works fine (e.g. inside a regular <div></div>)

Please provide a link to a minimal reproduction of the bug

Minimal reproduction in StackBlitz

Please provide the exception or error you saw

I see a blank spot where a HTML should be displayed instead

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 17.0.7
Node: 18.18.2
Package Manager: npm 9.8.1
OS: win32 x64

Angular: 17.0.7
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1700.7
@angular-devkit/build-angular   17.0.7
@angular-devkit/core            17.0.7
@angular-devkit/schematics      17.0.7
@angular/cdk                    16.0.1
@angular/material               16.0.1
@schematics/angular             17.0.7
ng-packagr                      17.0.2
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.2

Anything else?

No response

Activity

  1. JoostK commented on Dec 14, 2023

    @JoostK
    Member

    Please provide a minimum, runnable reproduction.

  2. added
    needs reproduction
    on Dec 14, 2023
  3. WarGreyGon commented on Dec 14, 2023

    @WarGreyGon
    Author

    @JoostK updated description with reproduction link 🙂

  4. JoostK commented on Dec 14, 2023

    @JoostK
    Member

    Thanks, that has been very helpful. It seems like the empty template is not considered for projection, as was done for the primary blocks of if and for in #52414.

  5. added
    area: core
    core: control flow
    and removed
    needs reproduction
    on Dec 14, 2023
  6. modified the milestone: needsTriage on Dec 14, 2023
  7. crisbeto commented on Dec 14, 2023

    @crisbeto
    Member

    This is currently "working as intended". The problem is that we use the main @for block as the insertion point both for the loop contents and the @empty contents.

  8. self-assigned this
    on Dec 18, 2023
  9. pkozlowski-opensource commented on Dec 18, 2023

    @pkozlowski-opensource
    Member

    The problem is that we use the main @for block as the insertion point both for the loop contents and the @empty contents.

    There was a refactoring at some point with which the main loop content and the empty blocks have their separate insertion containers. Capturing a tag name based on the empty block content (as we do for if, for etc.) should do the trick for the empty block as well.

  10. added
    P3
    on Dec 18, 2023
  11. modified the milestones: needsTriage, Backlog on Dec 18, 2023
  12. added a commit that references this issue on Dec 18, 2023
    9253e2f
  13. angular-automatic-lock-bot commented on Jan 19, 2024

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  14. locked and limited conversation to collaborators on Jan 19, 2024
  15. added a commit that references this issue on Jan 23, 2024
    78b0741
  16. added a commit that references this issue on Jan 26, 2024
    42ed6bc
  17. added a commit that references this issue on Jan 26, 2024
    ee8815d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3area: corebugcore: content projectioncore: control flowstate: has PR

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions