html - 如何制作嵌套的 ngFor?[角度和离子]
问题描述
我有一个嵌套的 ngFor,我想用它来渲染每个区域的项目。我怎样才能实现我的目标?如果我将第二个 ngFor 向上移动到 ion-segment-button 中,它会起作用,但是所有这些项目都会在我的按钮内呈现,这不是我想要的。
HTML
<app-toolbar *ngIf="template" [title]="template.Template_code"></app-toolbar>
<ion-content *ngIf="template" fullsreen>
<ion-grid fixed>
<!-- AREAS -->
<ion-row>
<ion-col size="12">
<!-- This ngFor works -->
<ion-segment
scrollable
(ionChange)="onAreaChange($event)"
value="{{ template.Version.Areas[0].Descriptions[0].Description }}"
>
<ion-segment-button
*ngFor="let area of template.Version.Areas"
value="{{ area.Descriptions[0].Description }}"
>
<ion-label>
{{ area.Descriptions[0].Description }}
</ion-label>
</ion-segment-button>
</ion-segment>
</ion-col>
</ion-row>
<!-- How do I make area work here? -->
<ion-row *ngFor="let item of area.Items">
<ion-col size="12">
<div>
{{ item }}
</div>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
解决方案
试试这个:
<ng-container *ngFor="let verArea of template.Version.Areas">
<ion-row>
<ion-col size="12">
<!-- This ngFor works -->
<ion-segment
scrollable
(ionChange)="onAreaChange($event)"
value="{{ template.Version.Areas[0].Descriptions[0].Description }}"
>
<ion-segment-button
*ngFor="let area of template.Version.Areas"
value="{{ area.Descriptions[0].Description }}"
>
<ion-label>
{{ area.Descriptions[0].Description }}
</ion-label>
</ion-segment-button>
</ion-segment>
</ion-col>
</ion-row>
</ng-container>
推荐阅读
- node.js - 在 Firebase 中按需下载文件
- javascript - 在闪亮的应用程序中将 Editor QR Scanner 包装到 DT 中
- reactjs - Strapi安装过程中依赖安装报错
- python - 如何在python上制作多项选择游戏
- ffmpeg - ffmpeg 多个输入 ss 仅在其中一个上
- azure-stream-analytics - Azure 流分析作业在使用静态引用数据时不生成输出
- go - 从文件中解析普罗米修斯指标并更新计数器
- powershell - 具有两个文本输入和下拉选择的 Powershell 表单
- php - 在 Telegram PHP API 中使用 Markdown 代码块
- sql - Postgres 关系查询