I'm trying to restrict a drag and drop based on the existing items in the drop list.
<div class="line" [cdkDropListEnterPredicate]="filledPosition" cdkDropList
#fwdLine1="cdkDropList" [cdkDropListData]="f1"
[cdkDropListConnectedTo]="[forwardPlayers]"
(cdkDropListDropped)="drop($event)">
<div *ngFor="let fwd of f1" cdkDrag [cdkDragData]="fwd">
<div class="player">
<span>{{fwd.number}} {{fwd.name}} {{fwd.position}}</span>
</div>
</div>
The issue is that I can't call an instance variable inside of the predicate function:
filledPosition(item: CdkDrag<Skater>) {
var currentPos = item.data.position;
for (let i = 0; i < this.f1.length; i++) {
if (this.f1[i].position == currentPos) {
return false
}
}
return true;
}
"this.f1" returns undefined even though I give it an empty array in the constructor. If this.f1 has a certain value, I want to restrict access to the drop list.
constructor() {
this.f1 = [];
}