Incremental migration to Angular’s new control flow syntax

incremental-migration-to-angular’s-new-control-flow-syntax

Angular v17 introduced a new control flow syntax that is built into the framework. The new syntax is about so-called “blocks” which are available in the template out of the box – meaning you don’t have to import anything to use them. These blocks are @if, @else if, @else, @for, @empty, @switch, @case and @default. I’m not going to explain them in details here. You can read more about each block in the official documentation.

The new syntax is currently in developer preview. Once it becomes stable, it’ll most likely become the recommended way to handle control flow in the template, thus deprecating the NgIf, NgFor and NgSwitch directives.

But despair not! Both options will be available for at least a few major versions, so nothing is going away overnight. You have planty of time to plan the migration.

Speaking of which, the Angular team has an official schematic to help you migrate 🎉

It’s also quite easy to run …

# Using Angular CLI
ng g @angular/core:control-flow

# Using Nx
nx g @angular/core:control-flow

The command proceeds to ask for a path to be migrated. The default is ./ (root) but you can set it to whatever you want. So you can either migrate the whole workspace at once or incrementally — step-by-step — one folder, feature or domain at a time.

Angular schematic to migrate to the new control flow syntax

Important: The schematic works amazingly well but you should absolutely go through the changes afterwards to be sure that everything is at it should.

Now go ahead and start using the new syntax. It’s great, I promise.

Thanks for reading. See you in the next post 😎

Photo by Nadine Shaabana on Unsplash

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
free-strategic-planning-templates-for-excel-and-word

Free Strategic Planning Templates for Excel and Word

Next Post
a-beginner’s-guide-to-contact-measurement-and-3d-scanning

A Beginner’s Guide to Contact Measurement and 3D Scanning

Related Posts
c++-指向類別成員的指位器的實作細節

C++ 指向類別成員的指位器的實作細節

C++ 可以定義指向成員函式的指位器, 不過因為成員函式可能是虛擬函式, 如何能夠透過指向成員函式的指位器達到呼叫正確的成員函式呢?本來就來簡單探究。(本文均以 g++ 為例, 並且只探討單純的單一繼承)。 指向非虛擬函式的指位器 首先來看個簡單的範例, 建立指向非虛擬函式的指位器: #include using namespace std; class A { public:…
Read More