举个栗子:
点击删除评论,删除后新增按钮(点击撤回)
html:
<button (click)="delComment()">删除</button>
<textarea *ngIf="Comment ; else Donotdel">每个人心里都有一团火,路过的人只看到烟</textarea>
//固定样式 ng-complate标签包裹else的情况 #跟else后的变量名
<ng-template #Donotdel>
//else的情况是 新增一个撤回按钮 点击后显示刚刚删除的内容
<button (click)="withDrow()">撤回删除</button>
</ng-template>
ts文件:
export class MyownComponent{
//默认显示评论
Comment=true;
//点击删除按钮
delComment(){
this.Comment=false;
}
点击撤回按钮
withDrow(){
this.Comment=true;
}
}
效果