In the new version of Angular V17, the @if
directive can be used as a replacement for ng-container
, which is fantastic. However, sometimes *ngIf
is more concise, such as when determining whether to display a button:
<button *ngIf="loaded">OK</button>
Therefore, I would like to ask, what is the outlook for *ngIf
? Will Angular completely abandon *ngIf
in some future version?
Should we replace all instances of *ngIf
with @if
now, even though the above code may not look as elegant as before?
@if(loaded){
<button>OK</button>
}
The
control_flow
concept is labeled as developer preview in Angular website which means:Also they have an efficient way of migrating from old template syntax to a new one introduced in Angular v17
Now let's get back to your questions:
Should we replace all instances of
*ngIf
with@if
?Will Angular completely abandon
*ngIf
in some future version?Side notes: By using
@If
you can get rid of usingng-template
which is really great feature. look at this example:With the built-in if statement, this condition will look like: