首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用@angular/cdk创建可拖动和可编辑的列表项?

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

Stack Overflow用户
提问于 2019-01-18 15:45:07
回答 1查看 384关注 0票数 0

我正在尝试创建一个水平的可拖动列表,其中的项目应该是可编辑的。为此,我使用了不带material和[contentEditable]='true'属性的cdk包。但这些项目不可编辑。我怎么才能让它工作?

代码语言:javascript
复制
<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有关,所以我添加了一个focus()调用:

代码语言:javascript
复制
onItemClick(event) {
    event.target.focus();
}

前台预览。用户应该能够编辑类型为“text”的项目:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-27 20:48:15

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54249632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档