There exists a service that handles the list data using `set/get` methods:
@Injectable()
export class ListService {
private items: any[] = [];
getItems() {
return this.items;
}
setItems<T>(items: T[]): T[] {
this.items = [...items];
return this.items;
}
setSelected(value: any): void {
value.selected = !value.selected;
}
setSelectedState(value: any, state: boolean): void {
value.selected = state;
}
drop(event: CdkDragDrop<string[]>) {
moveItemInArray(this.items, event.previousIndex, event.currentIndex);
}
emitChnages(): void {
this.onChanged.next(this.items);
}
}
I utilize this service within a component, where I assign the input variable `packet` to `this.listService.setItems()`:
export class SignComponent implements OnInit {
@Input() packet: any;
public copysogllist: any[] = [];
ngOnInit() {
this.copysogllist = this.listService.setItems(this.packet.sogllist);
}
public drop(event: CdkDragDrop<string[]>): void {
this.listService.drop(event);
}
}
Why is it that when I invoke `this.listService.drop(event);`, the array `this.copysogllist` does not get updated?