angular/packages/core/schematics/migrations/control-flow-migration
aparziale b96afb4bfc fix(migrations): handle reused templates in control flow migration (#63996)
The control flow migration was incorrectly removing `ng-template` elements in scenarios where they were referenced by multiple `*ngIf` directives' `else` clauses and also used independently via `ngTemplateOutlet`.

PR Close #63996
2025-09-24 16:01:58 +00:00
..
BUILD.bazel build: rename defaults2.bzl to defaults.bzl (#63383) 2025-08-25 15:45:01 -07:00
cases.ts refactor(migrations): centralize parseTemplate method (#62983) 2025-08-21 11:41:32 -07:00
fors.ts refactor(migrations): centralize parseTemplate method (#62983) 2025-08-21 11:41:32 -07:00
identifier-lookup.ts refactor(core): run the control flow migration during ng update (#60492) 2025-03-28 15:46:41 +00:00
ifs.ts refactor(migrations): centralize parseTemplate method (#62983) 2025-08-21 11:41:32 -07:00
index.ts refactor(migrations): centralize parseTemplate method (#62983) 2025-08-21 11:41:32 -07:00
migration.ts refactor(migrations): centralize parseTemplate method (#62983) 2025-08-21 11:41:32 -07:00
README.md refactor(core): run the control flow migration during ng update (#60492) 2025-03-28 15:46:41 +00:00
schema.json refactor(core): run the control flow migration during ng update (#60492) 2025-03-28 15:46:41 +00:00
switches.ts refactor(migrations): centralize parseTemplate method (#62983) 2025-08-21 11:41:32 -07:00
types.ts refactor(migrations): centralize parseTemplate method (#62983) 2025-08-21 11:41:32 -07:00
util.ts fix(migrations): handle reused templates in control flow migration (#63996) 2025-09-24 16:01:58 +00:00

Control Flow Syntax migration

Angular v17 introduces a new control flow syntax. This migration replaces the existing usages of *ngIf, *ngFor, and *ngSwitch to their equivalent block syntax. Existing ng-templates are preserved in case they are used elsewhere in the template. It has the following option:

  • path - Relative path within the project that the migration should apply to. Can be used to migrate specific sub-directories individually. Defaults to the project root.

Before

import {Component} from '@angular/core';

@Component({
  template: `<div><span *ngIf="show">Content here</span></div>`
})
export class MyComp {
  show = false;
}

After

import {Component} from '@angular/core';

@Component({
  template: `<div>@if (show) {<span>Content here</span>}</div>`
})
export class MyComp {
  show = false
}