我试图基于拖放列表中的现有项目来限制拖放。
<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>
问题在于我无法在谓词函数内部调用实例变量:
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”返回不确定,即使我在构造函数中给它一个空数组也是如此。如果this.f1具有某个值,我想限制对下拉列表的访问。
constructor() {
this.f1 = [];
}