【发布时间】: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();
}
前端预览。用户应该能够编辑“文本”类型的项目:
【问题讨论】:
-
请参阅this answer 以获得解决方案。
标签: angular typescript contenteditable angular-cdk