1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Getting the deprecation warning for ngIf/ngFor/ngSwitch/ngSwitchCase/ngSwitchDefault in my...

Discussão em 'Angular' iniciado por Naren Murali, Maio 30, 2025.

  1. Naren Murali

    Naren Murali Guest

    Trying out Angular 20.

    Getting the deprecation warning for all my control flow elements.


    'NgSwitchDefault' is deprecated.
    'NgSwitchCase' is deprecated.
    'NgSwitch' is deprecated.
    'NgFor' is deprecated.
    'NgIf' is deprecated.
    ​

    Screenshot of the deprecation warning.

    [​IMG]

    Below is a StackBlitz replicating the issue.

    import { Component } from '@angular/core';
    import { bootstrapApplication } from '@angular/platform-browser';
    import {
    NgIf,
    NgFor,
    NgSwitch,
    NgSwitchCase,
    NgSwitchDefault,
    } from '@angular/common';

    @Component({
    selector: 'app-root',
    imports: [NgIf, NgFor, NgSwitch, NgSwitchCase, NgSwitchDefault],
    template: `
    <button (click)="ifCondition = !ifCondition">Toggle Title</button>
    <h1 *ngIf="ifCondition">Hello from Angular 20!</h1>
    <hr/>
    <div *ngFor="let item of items; trackBy: trackBy; let i = index">
    <div>{{i}}. {{item}}</div>
    </div>
    <hr/>
    <ng-container [ngSwitch]="test">
    <ng-container *ngSwitchCase="'1'">
    Is One
    </ng-container>
    <ng-container *ngSwitchCase="'2'">
    Is Two
    </ng-container>
    <ng-container *ngSwitchDefault>
    Is Default
    </ng-container>
    </ng-container>
    `,
    })
    export class App {
    ifCondition = true;
    items = [1, 2, 3, 4, 5];
    test = '1';

    trackBy(index: number, item: any) {
    return index;
    }
    }

    bootstrapApplication(App);

    Stackblitz Demo

    Continue reading...

Compartilhe esta Página