在anuglar中使用ng-if else
文章目录
使用 else :
<div *ngIf="isValid;else other_content">
content here ...
</div>
<ng-template #other_content>other content here...</ng-template>
你也可以使用 then else :
<div *ngIf="isValid;then content else other_content">here is ignored</div>
<ng-template #content>content here...</ng-template>
<ng-template #other_content>other content here...</ng-template>
或者使用单独的 then :
<div *ngIf="isValid;then content"></div>
<ng-template #content>content here...</ng-template>
Demo示例 :

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论