我正在尝试使用打字稿在 Angular 应用程序中捕获 CKEditor5 内的输入。我能够让 CKEditor 显示并能够记录编辑器的存在。但是,我似乎无法捕获输入。这在 CKEditor4 中似乎非常简单,其中一个简单的代码如下所示:
editor.on('key', function (event) {
//some work goes here
}
然而,用我目前的 ClassicEditor 尝试这个似乎并非如此。我正在使用 Angular 并已在 index.html 中初始化 CKEditor5 并以以下格式从代码中调用它
declare var ClassicEditor: any;
export class AlterInput implements OnInit {
ngOnInit() {
ClassicEditor
.create( document.querySelector( '#editor' ) )
.then(editor => {
console.log("THIS GETS PRINTED", editor)
editor.on('key', (event) => {
console.log('THIS DOES NOT GET PRINTED', event);
})
.catch( error => {
console.error( error );
} );
}
}
我最初使用 CKEditor4 创建了一个插件 - 这是通过调用CKEDITOR.plugins.add('pluginName', {\**some work in the init function**\})
但是,我似乎找不到一个像样的例子来说明如何使用 CKEditor5 来做到这一点。我的最终目标是获取输入字符的键码,添加一个,然后粘贴。