Javascript *Angular 4中的ngFor在.shift()上返回以下错误:未捕获的TypeError:无法读取null的属性“destrocted”

Javascript *Angular 4中的ngFor在.shift()上返回以下错误:未捕获的TypeError:无法读取null的属性“destrocted”,javascript,angular,ionic-framework,ionic4,Javascript,Angular,Ionic Framework,Ionic4,删除对象数组中的第一个元素时,收到错误: 未捕获的TypeError:无法读取null的属性“已销毁” 这是从哪里来的 我的html页面: <ion-list> <ion-item *ngFor="let s of this.lastScores"> <ion-label> <ion-grid> <ion-row >

删除对象数组中的第一个元素时,收到错误:

未捕获的TypeError:无法读取null的属性“已销毁”

这是从哪里来的

我的html页面:

<ion-list>
    <ion-item *ngFor="let s of this.lastScores">
        <ion-label>
            <ion-grid>
                <ion-row >
                    <ion-col size="3">
                        {{s.score}}
                    </ion-col>
                    <ion-col size="3">
                        {{s.totalScore}}
                    </ion-col>
                    <ion-col size="6">
                        <small>{{s.newText}}</small>
                    </ion-col>
                </ion-row>
            </ion-grid>
        </ion-label>
    </ion-item>

</ion-list>
并将其删除如下:

this.lastScores.unshift({
    'score':      1,
    'newText':    'hello',
    'totalScore': 10,
})
this.lastScores.shift();
this.ref.detectChanges();

我使用构造函数private ref:ChangeDetectorRef中的this.ref.detectChanges,因为函数在.subscribe之后调用,需要更新DOM。

只需使用角度切片管道即可
<*ngFor=let s of lastScores | slice:0:1}

如果使用splice you而不是shift,是否仍会出错?。另外,如果您使用扩展syntex重新分配数组,则可能不需要执行诸如this.lastScores=[newvalue,…this.lastScores]Yes之类的菜单更改操作,再次出现相同的错误。我仍然需要对拼接进行检测更改,对吗?如果重新分配数组的变量,则不需要chnge detaction,而且我非常确定拼接时不需要menual change detaction。可能问题实际上在于change deaction,因为我没有其他想法。如果我不调用change detection,那么数组在DOM中不会更新。我在一个函数中使用它。Subscribery使用spread进行添加,使用splice进行删除,或者使用filter或split重新分配数组,并避免菜单更改deaction,也许它会起作用。这到底是做什么的?使用slice pipe删除数组中的对象遵循此链接我不想删除for循环中的任何内容。这不是问题所在