This is the latest control flow in angular 18.
@if(condition) {
<button>If Condition</button>
}
@else {
<button>Else Condition</button>
}
And This is the old way.
<ng-container *ngIf="state1; else default">State 1 selected</ng-container>
<ng-template #default> No state is selected. </ng-template>
Does this old way is still valid in angular 18 or not?
Yes, you can use the old method, it's a matter of preference.
The difference is that, we can use @if
, @for
directly without any imports.
But when doing *ngIf
or *ngFor
you need to import the CommonModule
, or the directives directly NgIf
, NgFor
from '@angular/core'
.