如何使用;ckeditor";以Angular2的形式反应?

如何使用;ckeditor";以Angular2的形式反应?,ckeditor,angular2-forms,angular-reactive-forms,Ckeditor,Angular2 Forms,Angular Reactive Forms,我在纽约安格拉尔。我正在使用ckeditor创建一个反应式表单。一切都很好,但我的编辑数据没有发布。它是空的。我是阅读指南和创建这个,但我不能得到完美的结果 我是用户表单[formGroup]createPage,并在此表单中使用ckditor。但我无法获得ckeditor的数据。如何使用表单从ckeditor获取数据。在表单提交按钮中单击 这是我的ckeditor.ts文件 import { Component, OnInit, Input } from '@angular/core'; @C

我在纽约安格拉尔。我正在使用ckeditor创建一个反应式表单。一切都很好,但我的编辑数据没有发布。它是空的。我是阅读指南和创建这个,但我不能得到完美的结果

我是用户表单[formGroup]createPage,并在此表单中使用ckditor。但我无法获得ckeditor的数据。如何使用表单从ckeditor获取数据。在表单提交按钮中单击

这是我的ckeditor.ts文件

import { Component, OnInit, Input } from '@angular/core';
@Component({
  selector: 'CKEDITOR',
  template: `
     <textarea name="targetId" id="targetId"  rows="rows" cols="cols">
         {{content}}
     </textarea>`
})
export class AdminCkeditorComponent implements OnInit {
  content: any = "test content";
  @Input() targetId;;
  @Input() rows = 10;
  @Input() cols;     
  constructor() { }
  ngOnInit(){
    window['CKEDITOR']['replace']( 'targetId' );
  }
}
这是html文件

 <form [formGroup]="createPage" (ngSubmit)="onSubmitPage()">
       <input type="text" name="pageTitle" formControlName="pageTitle" class="form-control">
       <input type="text" name="pageUrl" formControlName="pageUrl" class="form-control" >
       <textarea name="pageHeader" formControlName="pageHeader" class="form-control"></textarea>
       <CKEDITOR></CKEDITOR> 
       <button class="btn btn-info pull-right">Sign in</button>
</form>

登录

我正在使用Angular CLI,其中ckeditor5与NPM一起安装

此编辑器位于反应窗体内

我已经预先制作了输入、NgModel和设置变量,但您没有 看这里

您可以尝试将这些逻辑转换为Angular 2

代码: HTML:

为什么不简单地:

<form [formGroup]="form">
  <ckeditor [config]="config" formControlName="[YOUR_FORMCONTROL_NAME]"></ckeditor>
</form>

适合我。

HTML部分:
HTML Section:
    <div class="form-group">
            <label for="notification">Notification</label>
            <ckeditor [editor]="Editor" [config]="ckconfig" [formControl]="notification"  data="<p>Hello, world!</p>"></ckeditor>
        </div>


TS Section:
        //Import above
        import * as ClassicEditor from '@ckeditor/ckeditor5-build-classic';

        export class YourComponent implements OnInit {
        public Editor = ClassicEditor;
        ckconfig = {
            toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote' ],
          };

        }


    notification = new FormControl('',Validators.required);
通知 TS组: //进口高于 从“@ckeditor/ckeditor5 build classic”导入*作为ClassicEditor; 导出类YourComponent实现OnInit{ 公共编辑器=ClassicEditor; ckconfig={ 工具栏:[“标题”、“标题”、“粗体”、“斜体”、“链接”、“项目符号列表”、“数字列表”、“块引号”], }; } 通知=新表单控件(“”,需要验证程序);
就这样吧。
参考资料:

您找到sameCan的解决方案了吗?请告诉我验证的情况
// ...
change({ editor }: ChangeEvent) {
  const EditorData = editor.getData();

  this.form.get('description').setValue(EditorData);
}
<form [formGroup]="form">
  <ckeditor [config]="config" formControlName="[YOUR_FORMCONTROL_NAME]"></ckeditor>
</form>
HTML Section:
    <div class="form-group">
            <label for="notification">Notification</label>
            <ckeditor [editor]="Editor" [config]="ckconfig" [formControl]="notification"  data="<p>Hello, world!</p>"></ckeditor>
        </div>


TS Section:
        //Import above
        import * as ClassicEditor from '@ckeditor/ckeditor5-build-classic';

        export class YourComponent implements OnInit {
        public Editor = ClassicEditor;
        ckconfig = {
            toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote' ],
          };

        }


    notification = new FormControl('',Validators.required);