Skip to content

Prettier incorrectly adds a colon after ngIf else statement #15719

Closed

Description

@mattlewis92

Prettier 3.0.3
Playground link

--parser angular

Input:

<div *ngIf="item$ | async; let item; else loadingTemplate"></div>
<ng-template #loadingTemplate> Loading </ng-template>

Output:

<div *ngIf="item$ | async; let item; else: loadingTemplate"></div>
<ng-template #loadingTemplate> Loading </ng-template>

Expected behavior:

Colon is not added after the else statement, as according to the angular team this is not valid syntax: angular/angular#53150 (comment)

<div *ngIf="item$ | async; let item; else loadingTemplate"></div>
<ng-template #loadingTemplate> Loading </ng-template>

Activity

  1. M0ns1gn0r commented on Feb 12, 2024

    @M0ns1gn0r

    Having the same problem but with expression flavor:

    @if (tab.eventCount$ | async; as count) {
      <x />
    }
    

    gets converted to this after formatting:

    @if (tab.eventCount$ | async; as: count) {
      <x />
    }
    

    That additional colon breaks the template.

  2. added
    lang:angular
    status:needs investigation
    on Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:angularstatus:needs investigation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions