我想了一下怎么做。我将在这里记录它的机会,它将帮助有人在路上避免发现的过程中,我所经历的。
在源文件上我有一个
文本编辑器
元素如下:
<div *ngIf="document">
<ckeditor #ckEditor
[editor]="Editor" [config]="ckconfig" [disabled]="true"
[(ngModel)]="document.text"></ckeditor>
<button mat-flat-button (click)="clickPasteSelectedPlain(ckEditor)">Paste Selected Text Plain</button>
</div>
在组件中
点击
@Output() paste = new EventEmitter<PasteEvent>();
...
clickPasteSelectedPlain(editorComponent: CKEditorComponent) {
const editor = editorComponent.editorInstance;
this.paste.emit({
content: editor.model.getSelectedContent(editor.model.document.selection),
obj: this.document,
quote: false
});
}
粘贴事件
接口
为了节省空间,我将在这里省略。这个
内容
键将指向
DocumentFragment
.
请注意,我正在传递
CKEditorComponent
@视图子对象
文本编辑器
在一个
*ngIf公司
结构。我认为这在Angular 6中效果很好,但在过去我在这方面遇到了困难
当目标有条件地在DOM中时引用。这个方法总是有效的,但是你想用什么方法都行。
事件由
发出
使用如下方法处理:
doPaste(pasteEvent: PasteEvent, editorComponent: CKEditorComponent) {
const editor = editorComponent.editorInstance;
editor.model.insertContent(pasteEvent.content);
}
文档碎片
粘贴操作将包括所选源中包含的所有格式和文本属性。但就这些。