Angular 角度:在Ui中重置阵列而不重新加载视图

Angular 角度:在Ui中重置阵列而不重新加载视图,angular,typescript,Angular,Typescript,我目前有以下html代码: <ng-container *ngFor="let goal of goalList;> <tab> <h3 class="...">{{goal?.title}}</h3> <p class="...">{{goal?.description}}</p> </tab> </ng-container> 不幸的是,此时,当前值将消失,因为后面的数组将

我目前有以下html代码:

<ng-container *ngFor="let goal of goalList;>
  <tab>
    <h3 class="...">{{goal?.title}}</h3>
    <p class="...">{{goal?.description}}</p>
  </tab>
</ng-container>
不幸的是,此时,当前值将消失,因为后面的数组将被覆盖


是否可以更改组件中的数组,以自动刷新Ui中的值?

您可以创建另一个数组,并保存此数组中可观察值的答案

this.serviceExample.goalListObservable.subscribe(
  data => this.newArray = data
));
在frontent中,您使用已经用于ngFor的阵列,以及从第二个阵列中获取的数据:

<ng-container *ngFor="let goal of goalList; let i = index" [attr.data-index]="i">
  <tab>
    <ng-container *ngIf="newArray">
      <h3 class="...">{{newArray[i]?.title}}</h3>
      <p class="...">{{newArray[i]?.description}}</p>
    </ng-container>
  </tab>
</ng-container>

{{newArray[i]?.title}

{{newArray[i]?.description}


效果很好!!谢谢:)
<ng-container *ngFor="let goal of goalList; let i = index" [attr.data-index]="i">
  <tab>
    <ng-container *ngIf="newArray">
      <h3 class="...">{{newArray[i]?.title}}</h3>
      <p class="...">{{newArray[i]?.description}}</p>
    </ng-container>
  </tab>
</ng-container>