【问题标题】:displaying data nested within objects - angular显示嵌套在对象中的数据 - 角度
【发布时间】:2023-02-10 10:46:53
【问题描述】:

我正在尝试在我的角度前端显示我的数据集中的数据。我想显示的一些信息嵌套在对象对象中。正如您在下面看到的。我在显示经纬度值时遇到问题。我试过这个html:

                <ng-container *ngFor="let geometry of trail?.geometry">
                    <ng-container *ngFor="let location of geometry?.location">
                        <ng-container *ngFor="let lat of location?.lat">
                                {{ lat }}
                        </ng-container>
                    </ng-container>
                </ng-container>

【问题讨论】:

  • 有什么麻烦?你能展示数据示例吗?不清楚,为什么要使用 ngFor

标签: html angular mongodb


【解决方案1】:

如果我知道你需要在 html 中显示经纬度,但在你的代码中你试图迭代一个对象,这在这种情况下是不可能的,为了在你的 html 中显示经纬度你只需要访问关键经纬度你的对象,像这样:

<ng-container>
            {{ geometry.location.lat }}
 </ng-container>

如果需要在 lat 有值时显示 ng-container,则需要使用 *ngIf 进行验证。

我希望这对你有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-27
    • 2016-11-14
    • 2018-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-12
    相关资源
    最近更新 更多