I'm facing an issue with updating a record in my service where the changes are not being reflected in the component's data.
listData contains all the necessary information.
All variables have relevant data stored in them.
For example: 1, 1, my title, post text
The result is successfully returned to the service. However, I encounter an issue after that.
update(id, userId, title, body) {
this.apiService.updateById(id, userId, title, body).subscribe(
result => {
console.log(result);
// THE ISSUE BEGINS HERE
const currentItemIndex = this.listData.findIndex((item: {id: number}) => item.id === id);
console.log(`CurrentIndex is: ${currentItemIndex}`); // Returns -1
// THIS PART IS NEVER EXECUTED
if (currentItemIndex > -1) {
this.listData.splice(currentItemIndex, 0, {userId: userId, title: title, body: body});
}
},
error => {
console.log('There was an error: ', error); // No errors returned
}
);
}
Any suggestions on how I can resolve this? What could be causing the problem?