Keydown事件CKEditor使用实例

Keydown event CKEditor using instance

我想获取 ckeditor 的 keydown 事件,但要在 AngularJS 中使用实例。 我创建了一个指令并将 keydown 事件发送到我的范围函数。但是我的页面上有很多 ckeditor。每次按键,我都会得到所有 ckeditor 实例的按键事件。

指令:

app.directive('ckEditor', function () {
  return {
    require: '?ngModel',
    link: function (scope, elm, attr, ngModel) {
      var ck = CKEDITOR.replace(elm[0]);
      if (!ngModel) return;

      ck.on('pasteState', function() {
        scope.$apply(function() {
          ngModel.$setViewValue(ck.getData());
        });
        var editable = ck.editable();

        editable.attachListener( ck.document, 'keydown', function(event) {
            scope.keyboard_events(event);
        });
      });

      ngModel.$render = function(value) {
        ck.setData(ngModel.$viewValue);
      };

    }
  };
});

我的控制器:

$scope.keyboard_events = function(event) {
  console.log( "agora sim ")
}

我使用 angular-ckeditor 解决了我的问题。使用实例和 ng 模型要好得多。 (https://github.com/lemonde/angular-ckeditor)