Reputation: 15
I am trying to create a directive for CkEditor5, but it not change model value.
This is my code for directive:
.directive('ckEditor', function () {
return {
require: '?ngModel',
link: function (scope, element, attr, ngModel) {
if (!ngModel) return;
ClassicEditor.create(element[0]).then((editor) => {
editor.on('change', () => {
scope.$apply(() => {
ngModel.$setViewValue(editor.getData());
});
});
ngModel.$render = () => {
editor.setData(ngModel.$modelValue);
};
scope.$on('$destroy', () => {
editor.destroy();
});
});
}
}
})
The 'change' event doesn't do anything. Can anyone explain what is not correct here?
Upvotes: 1
Views: 1812
Reputation: 3664
You're not correctly binding to the underlying data change event for CKEditor.
Specifically,
editor.model.document('change:data', () => { /* ... */ });
Here's a working demonstration.
Upvotes: 2