How to add plugins to ng2-ckeditor using TypeScript and Angular 2 ?

我怕爱的太早我们不能终老 提交于 2019-12-06 05:05:43

问题


I'm trying to add the Justify plugin to my ckeditor, but unfortunately I can't find any information about how I should add plugins to ng2-ckeditor.

Also I'm not able to find any directory or config file where I should add plugins.

I'm using ng2-ckeditor 1.0.6 with TypeScript.


回答1:


ng-ckeditor uses the CKEditor CDN. This page shows you how to add external plugins either from the cdn or downloading the plugin and using a local version.

declare var CKEDITOR: any;

CKEDITOR.plugins.addExternal(
  'uploadimage',
  '../full-all/plugins/divarea/',
  'plugin.js');

This is accessing the full-all path on the cdn. alternatively if you want to access it from a local folder you would make the path something like /users/app/assets/...etc depending on where your downloaded folder is located.

In your html you'd add the following: [config]="{extraPlugins: 'divarea'}" to your ckeditor tag.

Since most Angular2 use cases need the divarea plugin by default due to crash issues, any other plugins you add need to be inserted as a comma-separated string:

[config]="{extraPlugins: 'divarea,uploadimage'}"

If binding to a local component variable, for example, it would be like this:

this.ckConfig = {
  height: '250',
  extraPlugins: 'divarea,uploadimage',
  enterMode: '2',
  toolbar: [
    {name: 'document', items: ['Source', '-']},
    {name: 'clipboard', items: ['Undo', 'Redo']},
    {name: 'paragraph', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight']},
    {name: 'insert', items: ['Image']},
    {name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', '-']},
    {name: 'styles', items: ['Font', 'FontSize']},
    {name: 'colors', items: [ 'TextColor' ]},
  ]
};

NOTE - do not leave a space after the comma. In fact NO spaces in that string, it has to be 'pluginname,pluginname,pluginname' ...etc...



来源:https://stackoverflow.com/questions/39446203/how-to-add-plugins-to-ng2-ckeditor-using-typescript-and-angular-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!