【发布时间】:2021-09-30 15:57:20
【问题描述】:
我有点被我的问题困住了。我正在处理这样的视图:
我正在从 API 获取数据,因此我将有多个选项和子选项。但是,我希望仅在选中父复选框时才出现子选项。我尝试使用 *ngIf:
<ul *ngFor="let job of jobs; let i = index">
<input type="checkbox" id="{{i}}" value="{{job.name}}"><label
for="{{i}}">{{job.name}}</label>
<ul *ngIf="CONDITION HERE">
<li *ngFor="let child of job.children"><label><input type="checkbox">
{{child.name}}</label></li>
<li *ngFor="let child of job.children"><label><input type="checkbox">
{{child.name}}</label></li>
</ul>
</ul>
但我无法确定我可以使用什么条件。有没有简单的解决方案来解决这个问题?
@edit 让我澄清一下。我可能有多个这样的选择:
使用标志是行不通的,因为每个父选项都必须使用唯一的布尔变量。
【问题讨论】:
标签: html angular angular-ng-if