微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CKEditor 5:如何在Angular应用程序中访问原始文本

如何解决CKEditor 5:如何在Angular应用程序中访问原始文本

我在Angular应用程序中使用CKEditor 5。我必须检查用户在编辑器中输入的文本至少有100个字符。问题在于绑定到编辑器的模型会接收文本+编辑器创建的用于格式化的html标记。因此,我想以某种方式将模型的第二个属性绑定到编辑器的原始文本。这可能吗?

在我的组件中,我可以像这样访问编辑器:

 @ViewChild('ckeditor',{ static: true }) private _ckEditor: CKEditorComponent;

我已经尝试过将其作为测试,但是找不到原始文本:

  onBlur() {
   console.log( this._ckEditor.editorInstance.document.getBody().getText());
  }

和html:

<ckeditor #ckeditor id="desc" name="desc" [editor]="editor" (blur)="onBlur()"
                [(ngModel)]="mymodel"></ckeditor>

解决方法

CK Editor 5 现在提供 Word Count Plugin,可用于统计编辑器中输入的单词和字符。

enter image description here

文档链接:https://ckeditor.com/docs/ckeditor5/latest/features/word-count.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。