Angular CKEditor 5 指令无效

Angular directive for CKEditor 5 not working

我正在尝试为 CkEditor5 创建指令,但它不会更改模型值。

这是我的指令代码:

      .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();
                });
            });
        }
    }
})

'change' 事件不执行任何操作。谁能解释这里不正确的地方?

您没有正确绑定到 CKEditor 的基础数据更改事件。

具体来说,

editor.model.document('change:data', () => { /* ... */ });

Here's a working demonstration.