I am trying to set the contents of my editor from my api call (using an ajax request), however, it won't update the editor. I'm not sure why because when I do
alert(data.content) -- it returns {"ops":[{"insert":"Test 123\n"}]}
and
quill.setContents({"ops":[{"insert":"Test 123\n"}]}, 'api');
works as expected, however, nothing happens when I do
quill.setContents(data.content, 'api')
Any ideas? Thanks!
setContents from APi is working.
var quill = new Quill('#editor-container', {
modules: {
toolbar: [
[{ header: [1, 2, false] }],
['bold', 'italic', 'underline'],
['image', 'code-block']
]
},
placeholder: 'Compose an epic...',
theme: 'snow' // or 'bubble'
});
var ops = [
{ insert: 'Hello ' },
{ insert: 'World!', attributes: { bold: true } },
{ insert: '\n' }
];
quill.setContents(ops, 'api');
You are probably passing a string instead of an object.
Try calling JSON.parse(data.content) to convert the string to an object.