Я пытаюсь удалить объект из массива, используя индекс, а затем обновляю список. Однако сплайс не удаляет ожидаемый объект.
В моем компоненте редактирования:
onDelete() {
const index = this.actRoute.snapshot.params.id;
this.riverSvc.removeRiver(index);
}
В моем сервисе:
private storedRivers: RiverInfo[] = [
{
name: 'Cartecay',
address: 'Lower Cartecay Road',
currentFlow: 2.78,
desiredMin: 1.5,
desiredMax: 6
},
{
name: 'Etowah',
currentFlow: 857,
desiredMin: 100,
desiredMax: 500
},
{
name: 'Yellow',
address: 'Brown Bridge Road',
currentFlow: 2800,
desiredMin: 400,
desiredMax: 3000
}
];
removeRiver(index: number) {
console.log(index); // index is correct in the console.
this.storedRivers.splice(index, 1);
console.log(this.storedRivers);
this.watchedRiversChanged.next(this.storedRivers);
}
В моем компоненте списка:
ngOnInit() {
this.subscription = this.riverSvc.watchedRiversChanged
.subscribe((myRivers: RiverInfo[]) => {
this.riverWatchList = myRivers;
});
this.riverWatchList = this.riverSvc.watchedRivers();
}