As you know in angular 17 we can have different syntax for ngIf
, ngFor
and so on. Am looking for an efficient way of migrating old syntax in html files to the new on presented in Angular 17:
For example I had this old html in angular 15:
<ng-container *ngIf="!dynamicWidth; else FlexibleRef">
<div class="c-title"></div>
<div class="c-desc c-desc__short"></div>
<div class="c-desc c-desc__long"></div>
</ng-container>
<ng-template #FlexibleRef>
<div
*ngFor="let item of count | numberRange; let i = index"
[ngStyle]="{ width: (100 / count) * (i + 1) + '%' }"
class="flexible-desc"></div>
</ng-template>
And need it in the new syntax like this:
@if (!dynamicWidth) {
<div class="c-title"></div>
<div class="c-desc c-desc__short"></div>
<div class="c-desc c-desc__long"></div>
} @else {
@for (item of count | numberRange; track item; let i = $index) {
<div [ngStyle]="{ width: (100 / count) * (i + 1) + '%' }" class="flexible-desc">. </div>
}
}