角数组项未定义,但仍然有效吗?

时间:2020-04-05 18:02:49

标签: google-cloud-firestore iteration undefined-behavior angular9

由于某种原因,当我遍历数组时,结果变得不确定。该数组是将FIRESTORE QUERY传递给函数的结果。我不知道是什么原因引起的。

这里有一些代码片段,我省略了一些不必要的细节。

HTML(仅使用ngFor显示卡片组)

<ion-col *ngFor="let deck of decks" class="ion-text-center">
   <ion-label>{{ deck.title }}</ion-label>
   <ion-row *ngIf="currentDeck">
       <app-card-toggle *ngFor="let card of deck.cards" [isInCurrentDeck]="isInDeck(card, currentDeck)"
           [cardData]="card" (toggleEvent)="modifyDeck($event)">
       </app-card-toggle>
   </ion-row>
</ion-col>

TS(给我带来麻烦的功能)

partitionDecks(decks: Deck[]) {
    console.log(decks);
    console.log(decks[0]);
    ...

console.log(甲板)的结果。这是理想的行为

working perfectly fine

console.log(decks [0])的结果

somehow undefined?

正在调用函数的地方

enter image description here

为什么第一个元素未定义?

  • 使用JavaScript传播运算符不起作用。结果为空数组。
  • 简单的“ for”循环甚至无法识别数组的元素
  • “甲板”在HTML中是可用的,只要不被操纵....为什么?

0 个答案:

没有答案
相关问题