【问题标题】:Error while building an angular project for Tuple type '[]' of length '0' has no element at index '0'为长度为“0”的元组类型“[]”构建角度项目时出错,索引“0”处没有元素
【发布时间】:2021-03-17 01:30:38
【问题描述】:

以下是我执行以下prod命令时的错误

ng build --prod

src/app/inventory/inv-parts-main-table/dialog-component/dialog-component.component.html(5,16) 中的错误:长度为 '0' 的元组类型 '[]' 没有元素在索引“0”处。

src/app/inventory/inv-parts-main-table/dialog-component/dialog-component.component.html(5,62):长度为“0”的元组类型“[]”在索引处没有元素'0'。

src/app/inventory/inv-parts-main-table/dialog-component/dialog-component.component.html(5,62):长度为“0”的元组类型“[]”在索引处没有元素'0'。

src/app/inventory/inv-parts-main-table/dialog-component/dialog-component.component.html(9,16):长度为“0”的元组类型“[]”在索引处没有元素'1'。

src/app/inventory/inv-parts-main-table/dialog-component/dialog-component.component.html(9,62):长度为“0”的元组类型“[]”在索引处没有元素'1'。

src/app/inventory/inv-parts-main-table/dialog-component/dialog-component.component.html(9,62):长度为“0”的元组类型“[]”在索引处没有元素'1'。

src/app/inventory/inv-parts-main-table/dialog-component/dialog-component.component.html(13,16):长度为“0”的元组类型“[]”在索引处没有元素'2'。

src/app/inventory/inv-parts-main-table/dialog-component/dialog-component.component.html(13,62):长度为“0”的元组类型“[]”在索引处没有元素'2'。

src/app/inventory/inv-parts-main-table/dialog-component/dialog-component.component.html(13,62):长度为“0”的元组类型“[]”在索引处没有元素'2'。

上述错误相关的源码如下所示

<div mat-dialog-content>
    <div style="margin-top: 30pt" *ngIf="data.quote[0]!=null">
      <span><b>{{data.quote[0] | currency}}</b></span> <br />
      {{data.lastUpdatedDate[0] | date :'mediumDate'}} | {{data.supplierName[0]}}
    </div>
    <div style="margin-top: 10pt" *ngIf="data.quote[1]!=null">
      <span><b>{{data.quote[1] | currency}}</b></span> <br />
      {{data.lastUpdatedDate[1] | date :'mediumDate'}} | {{data.supplierName[1]}}
    </div>
    <div style="margin-top: 10pt" *ngIf="data.quote[2]!=null">
      <span><b>{{data.quote[2] | currency}}</b></span> <br />
      {{data.lastUpdatedDate[2] | date :'mediumDate'}} | {{data.supplierName[2]}}
    </div>
</div>

Ts 文件如下所示

export interface DialogData {
  quote: [];
  lastUpdatedDate : [];
  supplierName: [];
}

【问题讨论】:

    标签: javascript angular typescript


    【解决方案1】:

    以下 ts 更改帮助我解决了这个问题

    长度为“0”的元组类型“[]”在索引“1”处没有元素。

    export interface DialogData {
      quote: string[];
      lastUpdatedDate : string[];
      supplierName: string[];
    }
    

    【讨论】:

      猜你喜欢
      • 2018-12-02
      • 1970-01-01
      • 2020-08-27
      • 2019-11-23
      • 2023-03-06
      • 2015-07-11
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      相关资源
      最近更新 更多