【问题标题】:How to create draggable and editable list items using @angular/cdk?如何使用@angular/cdk 创建可拖动和可编辑的列表项?
【发布时间】:2019-01-18 07:45:06
【问题描述】:

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

<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();
}

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

【问题讨论】:

标签: angular typescript contenteditable angular-cdk


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-13
    相关资源
    最近更新 更多