I get the following error: ERROR TypeError: Cannot assign to read only property '2' of string 'One'
from the following datalist that I created to mimic the form that my actual data looks like, and the template view that I have seen to use from angular material documentation for dynamic lists like these. But even though they say what to do, they do not give an example..
I can not get the following to work:
Component:
lists = [];
ngOnInit() {
this.lists = [{number: 'One', amount: [1, 2, 3, 4]}, {number: 'Two', amount: [5, 6, 7, 8]}, {number: 'Three', amount: [9, 10, 11, 12]}];
}
drop(event: CdkDragDrop<string[]>) {
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);
}
}
Template:
<div cdkDropList [cdkDropListData]="list.number" *ngFor="let list of lists" (cdkDropListDropped)="drop($event)">
{{list.number}}
<div cdkDrag [cdkDragData]="item" *ngFor="let item of list.amount">
{{item}}
</div>
</div>