How to set Data with document editor in CKEditor 5

2.2k views Asked by At

I create a system to save the document by cookie, everything works well, but I just miss how to put the text on the document ... I have a DecoupledEditor, but when I try to make DecoupledEditor.setData (cookie) it tells me that setData does not exist! Have a nice day

DecoupledEditor.setData(docu);

To get the editor

DecoupledEditor
    .create( document.querySelector.....
1

There are 1 answers

4
Toxnyc On BEST ANSWER

Something like this.

(async function() {
  try {
    const editor = await DecoupledEditor
                   .create( document.querySelector( '#editor' ));
    editor.setData('This text is generated from setdata() method.');
  } catch(e) {
    console.error(e);
  }
 })();
<script src="https://cdn.ckeditor.com/ckeditor5/23.0.0/decoupled-document/ckeditor.js"></script>

<h1>ckeditor</h1>
<div  id="editor">
   Default Text
</div>

Doc Refrenence