I'm using the new Angular 7 Material CDK drag-drop feature to move item from a list to another and visually everything rocks when moving those but when changing item through lists I'm getting an error saying can't get a property (the list array) from undefined, even if I'm using the "item?.array" thing
in constructor:
this.userService.getUserById('some-user-id').subscribe(user => {
this.user1 = user;
console.log(user1.route.routePoints); // I see the array in log
});
this.userService.getUserById('some-other-user-id').subscribe(user => {
this.user2 = user;
console.log(user2.route.routePoints); // I see the array in log
});
Here I'm getting the error "Cannot read property 'routePoints' of undefined" when dragging item from a list to another
<div cdkDropList #routeA="cdkDropList" cdkDropListOrientation="horizontal"
[cdkDropListData]="user1?.route?.routePoints"
class="list" (cdkDropListDropped)="drop($event, false, user1)"
[cdkDropListConnectedTo]="[queue, routeB]">
Here's the drag code:
drop(event: CdkDragDrop<RoutePoint[]>, fromQueue: boolean = false, user: User) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
transferArrayItem(event.previousContainer.data, event.container.data, event.previousIndex, event.currentIndex);
}
this.userService.updateUser(user);
}