Angular directive for CkEditor5 not working

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 don’t do anything. Can anyone explain what is not correct here?

Source: AngularJS

Related Post