我正在为我的项目使用以下代码。我想使用按钮切换(显示/隐藏)div。该分区及其按钮是使用ngFor生成的。
<div *ngFor="let room of roomDetail; let i = index">
<span *ngFor="let key of room | keys">
{{key}} : {{room[key]}} <button id="toggleDiv"> Show/Hide</button>
</span>
</div>>
答案 0 :(得分:0)
在房间中添加可见的属性,然后点击
<div *ngFor="let room of roomDetail; let i = index">
<span *ngFor="let key of room | keys">
<ng-container *ngIf="room.visible">{{key}} : {{room[key]}}</ng-container> <button id="toggleDiv" (click)="room.visible = !room.visible"> Show/Hide</button>
</span>
</div>