PrimeNG Quill编辑器最大长度

时间:2017-03-29 08:28:04

标签: angular primeng quill

我正在尝试为编辑器实现最大长度。我的代码是这样的:

this.editorTextChange$$ = this.quillEditor.onTextChange.asObservable()
  .subscribe((ev) => {
    const limit = this.maxLength;
    // last char is \n, so don't count it
    if (ev.textValue.length > limit) {
      this.quillEditor.quill.deleteText(limit, ev.textValue.length);
    }
    // last char is \n, so don't count it
    this.currentLength = this.quillEditor.quill.getLength() - 1;
  });
<p-editor
    #quill
    [(ngModel)] = htmlValue>
    <p-header>
      <span>
        <button title="Bold" class = "ql-bold"></button>
        <button title="Italic" class = "ql-italic"></button>
        <button title="Underline" class = "ql-underline"></button>
        <button title="Link" class = "ql-link"></button>
      </span>
    </p-header>
  </p-editor>

事情是编辑器在视图上更新,但模型保持不变。

如何更新?

谢谢!

1 个答案:

答案 0 :(得分:0)

this.quillEditor.quill.deleteText(limit, ev.textValue.length);之后, 添加以下代码

this.quillEditor.onModelChange(this.quillEditor.root.innerHTML); this.quillEditor..onModelTouched();