【问题标题】:No index signature with a parameter of type 'number' was found on type 'Number'在“数字”类型上找不到具有“数字”类型参数的索引签名
【发布时间】:2021-10-21 10:04:26
【问题描述】:

我有 2 个 *ngFor,每个都有 2 个索引。

<ng-container *ngFor="let groupItems of item.itemsList | groupBy: 'category'; index as i">
    <div class="field-view">
        <div class="label-view">
            {{ groupItems.groupName }}
        </div>
    </div>
    <ng-container *ngFor="let item of groupItems.items; index as j">
        <div class="field-view" [itemValue]="item.total">
                  <div class="value-view">
                    {{ item.total }}
                  </div>
               </div>
    </ng-container>
</ng-container>

我想把ij的总索引 我尝试使用[itemValue]="item.total[i][j]"{{ item.total[i][j] }} 但显示错误No index signature with a parameter of type 'number' was found on type 'Number'.

你能告诉我任何想法吗?

我有这个乔恩:

[
    {
      "id":3,
        "itemsList": [
            {
                "total": 20000,
                "itemId": "123",
                "category": "test"
            }
        ]
    },
    {
        "id":2,
        "itemsList": [
            {
                "total": 2000,
                "itemId": "235",
                "category": "test1"
            }
        ]
    },
    {
        "id":1,
        "itemsList": [
            {
                "total": 200,
                "itemId": "5452",
                "category": "test"
            }
        ]
    }
]

【问题讨论】:

  • 能分享一下item.itemsList的值吗?
  • 是的,我分享它。谢谢
  • 您有对象 item.itemList 或 itemValue 的类型定义吗?可以分享一下吗?

标签: angular typescript indexing ngfor


【解决方案1】:

从提供的信息来看,这看起来像是一个打字不匹配的问题。 请记住,类型 Number 与 number 不同:

  • Number 是一个环绕数字的 Object。
  • 数字是原始数据类型

这里有一些documentation,您可以查看。

确保您没有在类型定义中混合使用这两者。您可以将 number 分配给 Number,但反过来就不行了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-06
    • 1970-01-01
    • 1970-01-01
    • 2021-10-16
    • 2021-06-27
    • 2021-12-04
    • 2023-04-10
    • 2021-11-27
    相关资源
    最近更新 更多