ng2-ckeditor使用typescript和angular 2.0添加占位符插件

时间:2016-08-29 14:32:09

标签: javascript angularjs angular typescript ckeditor

我正在尝试在CKEditor工具栏中获取占位符插件,但在将extraPlugins:'placeholder'添加到CKEditor配置时出现以下错误 -

Error: [CKEDITOR.resourceManager.load] Resource name "placeholder" was not found at "//cdn.ckeditor.com/4.5.9/standard/plugins/placeholder/plugin.js?t=G6DD".

这是控制台日志截图 - enter image description here

我还创建了一个plunker

我已经通过npm安装了" ng2-ckeditor":" ^ 1.0.4"

我可以得到一些帮助吗?

2 个答案:

答案 0 :(得分:2)

你应该使用它:

<script src="https://cdn.ckeditor.com/4.5.11/full-all/ckeditor.js"></script>

你应该在你的CKEdior标签中使用:

<ckeditor
  [(ngModel)]="sampleContent"
  [config]="{uiColor: '#a0a0a0',extraPlugins:'placeholder'}"
  debounce="500">
</ckeditor>

你可以使用:

(change)="onChange($event)"

但您必须在您的组件中定义:

onChange(body:any) {
 //your Code
}

答案 1 :(得分:0)

如果要使用占位符或其他插件,则必须执行以下操作

1-转到此页面(https://ckeditor.com/cke4/addons/plugins/all)并下载您的插件(如占位符)并将其放置在项目的资产文件夹中

2-包括来自CDN (在index.html中)的 ckeditor

  <script src="https://cdn.ckeditor.com/4.12.1/full-all/ckeditor.js"></script>

3-引用占位符插件(在index.html中)

  <script src="./assets/ckediotr/plugins/placeholder/plugin.js"></script>

现在,该使用它了

在app.component中:

export class AppComponent implements OnInit {
  ckeditorContent = 'angualrckeditor';
  ngOnInit(): void {
    CKEDITOR.on('instanceCreated', function (event, data) {
      var editor = event.editor,
        element = editor.element;
      editor.name = "content"
    });
  }
}

在app.component.html

<form #form="ngForm">
 <ckeditor #myEditor [(ngModel)]="ckeditorContent" name="ckeditorContent"
  [config]="{uiColor: '#a4a4a4' , allowedContent: false,forcePasteAsPlainText: false , extraPlugins: 'placeholder'}"
  debounce="500"> </ckeditor>
</form>