首页 > 解决方案 > 如何在 angularJS 中将羽毛笔编辑器的文本字符限制限制为最多 5000 个字符?

问题描述

这是我的html代码。我如何限制用户输入最多 5000 个字符。

<div class="ql-container ql-bubble" id="richTextQuel">
  <ng-quill-editor theme="bubble" id="richTextEditor" placeholder="Inclusions" ng-model="title" modules="richTextEditorModules" class="ng-pristine ng-untouched ng-valid ng-isolate-scope 
                             ng-not-empty">
  </ng-quill-editor>
</div>

标签: angularjsquillmaxlength

解决方案


这是 Angular 2+ 和 PrimeNG 的解决方案,但您可以更改它以适合您的解决方案:

this.editor.getQuill().root.addEventListener('keydown', ($event) => this.checkLength($event));

其中 checkLength 是:

checkLength($event) {
    if (this.editor.getQuill().root.innerHTML.length >= 15) {
        $event.preventDefault();
    }
}

推荐阅读