不用 control flow 的写法
<div *ngIf="loggedIn; else anonymousUser">
The user is logged in
</div>
<ng-template #anonymousUser>
The user is not logged in
</ng-template>
使用 control flow 的写法
@if (loggedIn) {
The user is logged in
} @else {
The user is not logged in
}
如何将现有项目中的已有 angular 代码快速地迁移至 control flow 写法?
angular cli 提供了专门的迁移命令
ng g @angular/core:control-flow