如何使用@ angular / cdk创建可拖动和可编辑的列表项?

时间:2019-01-18 07:45:07

标签: angular typescript contenteditable angular-cdk

我正在尝试创建一个水平可拖动列表,其中应包含可编辑的项目。为此,我使用的是cdk软件包,没有材料,属性为[contentEditable]='true'。但是项目不可编辑。如何使它正常工作?

<div cdkDropList [cdkDropListOrientation]="'horizontal'" class="namingConventionDragDrop"
     (cdkDropListDropped)="drop($event)">
    <ng-container *ngFor="let item of resultConvention; let i = index;">
        <div cdkDrag class="pop naming-placeholder" *ngIf="item.type === 'placeholder'">
                {{item.value}}
            <fa-icon (click)="remove(i)" icon="times-circle"></fa-icon>
        </div>
        <div cdkDrag class="pop" *ngIf="item.type === 'text'
           [contentEditable]="true" (click)="onItemClick($event)">
                {{item.value}}
            <fa-icon (click)="remove(i)" icon="times-circle"></fa-icon>
        </div>
        <div class="pop deactivated" *ngIf="item.type === 'extension'">
            {{item.value}}
        </div>
    </ng-container>
</div>
<div class="naming-convention preview">
    <span>Preview:</span>
    {{preview}}
</div>

因为我认为这与焦点有关,所以我添加了一个focus()调用:

onItemClick(event) {
    event.target.focus();
}

前端预览。用户应该能够编辑“文本”类型的项目:

Preview of the frontend. The user should be able to drag & drop items and to edit items of type "text" (e.g. the first one)

1 个答案:

答案 0 :(得分:0)

有角度的CDK似乎吸收了左击事件。一种选择是使用右键单击进行编辑。