Angular 6 中 ngIf 中的多个条件 [英] Multiple Conditions in ngIf in Angular 6
问题描述
我想隐藏一个 div 并想显示另一个我在代码下面写的
我的问题是我在 ngIf 中使用了多个条件但无法正常工作.单击显示子内容 1"后,我想隐藏主要内容并希望显示所有按钮的子内容 1",反之亦然.我该怎么做.请帮忙.
你刚刚接近你的结果,查看你的代码看起来你正在学习,干得好!!您必须检查是否启用了任何一项内容,因此您需要隐藏所有三个按钮并显示您的子内容.以下是根据您的要求正确的代码,
<!-- 禁用显示所有子内容.--><div *ngIf="!showSubContent && !showSubContentTwo && !showSubContentThree"><button (click)="showSubContent=!showSubContent">显示子内容1</button><button (click)="showSubContentTwo=!showSubContentTwo">显示子内容2</button><button (click)="showSubContentThree=!showSubContentThree">显示子内容3</button><h2>主要内容
<!-- 在启用 SubContent-1 时显示.--><div *ngIf="showSubContent && !showSubContentTwo && !showSubContentThree">子内容 1 在这里<button (click)="showSubContent=!showSubContent">显示主要内容</button>
<!-- 如果启用了 SubContent-2,则显示.--><div *ngIf="showSubContentTwo && !showSubContent && !showSubContentThree">子内容 2 在这里<button (click)="showSubContentTwo=!showSubContentTwo">显示主要内容</button>
<!-- 如果启用了 SubContent-3,则显示.--><div *ngIf="showSubContentThree && !showSubContentTwo && !showSubContent">子内容 3 在这里<button (click)="showSubContentThree=!showSubContentThree">显示主要内容</button>