我已经实现了CKeditor,但是在编辑器的特定位置添加数据时遇到了麻烦。我遍历了CKeditor文档,所有代码都包含CKEDITOR关键字,因此我可以在哪里以及如何应用它。就像在这个http://zkfiddle.org/sample/22fu1pr/4-Insert-text-at-cursor-for-CKEditor#source-1中一样,但是有角度的实现
我尝试使用ID
HTML
<div class="row mb-3">
<form role="form"
#myForm="ngForm" accept-charset="UTF-8" novalidate>
<div
class="form-group has-feedback"
[ngClass]="{ 'has-error': myckeditor.invalid && myckeditor.touched }">
<ckeditor [(ngModel)]="mycontent"
#myckeditor="ngModel"
id = "myckeditor"
name="myckeditor"
required
[config]="ckeConfig"
debounce="500">
</ckeditor>
<div
*ngIf="myckeditor.invalid && myckeditor.touched" class="help-
block">Required field.</div>
</div>
</form>
</div>
<div class="row mb-3">
<button class="btn btn-secondary mr-2 ml-2" (click)="addValue()">CustomerNo</button>
</div>
ts
export class AppComponent {
name = 'ng2-ckeditor';
ckeConfig: any;
mycontent: string;
log: string = '';
@ViewChild("myckeditor") ckeditor: any;
constructor() {
this.mycontent = `<p>My html content</p>`;
}
ngOnInit() {
this.ckeConfig = {
allowedContent: false,
extraPlugins: 'divarea',
forcePasteAsPlainText: true
};
}
public addValue(): void {
this.CKEDITOR.instances['myckeditor'].setData('<p>This is the
editor data.</p>');
}
}
我希望能够通过单击按钮或使用超链接将值动态添加到CKeditor。
答案 0 :(得分:1)
#myckeditor="ngModel"
限制了ckeditor的功能,因此请使用#myckeditor
,并在ts
上使用@ViewChild('ckeditor') public ckeditor: any;
来访问编辑器并只需执行{{1} }将文本插入到光标指针位置。
https://ckeditor.com/old/forums/CKEditor-3.x/heres-how-insert-text-and-tags-cursor