question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CKEditor is empty if ngModel is populated before `instanceready`

See original GitHub issue

Using <ckeditor> the way the example shows seems to exhibit a problem:

import { Component } from '@angular/core';

@Component({
  selector: 'sample',
  template: `
  <ckeditor
    [(ngModel)]="ckeditorContent"
    [config]="{uiColor: '#99000'}"
    (change)="onChange($event)"
    (ready)="onReady($event)"
    (focus)="onFocus($event)"
    (blur)="onBlur($event)"
    debounce="500">
  </ckeditor>
  `
})
export class Sample{
  constructor(){
    this.ckeditorContent = `<p>My HTML</p>`;
  }
}

If my ngModel value is set before the CKEditor’s instanceready event has fired, my CKEditor element will be blank.

I noticed this on my page when my Web Service call returns data before my CKEditor’s instanceready event has fired. I worked around it by calling my Web Service only after the instanceready event, like this:

import { Component } from '@angular/core';

@Component({
  selector: 'sample',
  template: `
  <ckeditor
    [(ngModel)]="ckeditorContent"
    [config]="{uiColor: '#99000'}"
    (change)="onChange($event)"
    (ready)="onReady($event)"
    (focus)="onFocus($event)"
    (blur)="onBlur($event)"
    debounce="500">
  </ckeditor>
  `
})
export class Sample{
  ckeditorContent = '';
  constructor(){}
  onReady() {
    this.ckeditorContent = `<p>My HTML</p>`;
  }
}

Has anyone else encountered the same problem?

I am using ng2-ckeditor@1.1.8 and CKEDITOR@4.6.2.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
kzimnycommented, Dec 27, 2017

I have updated your plunker. Is that what you are looking for? If you model value change between initial instatiation and component initialization, you can change the value in onReady() event like that:

import {Component, ViewChild} from '@angular/core';

@Component({
  selector: 'my-app',
  template: `
    <ckeditor [(ngModel)]="content" debounce="500" (ready)="onReady($event)" #ckeditor>
      <p>Hello <strong>world</strong></p>
    </ckeditor>
    <div [innerHTML]="content"></div>
  `,
})
export class App {
  
  @ViewChild("ckeditor") ckeditor: any;
  content: string;
  myModelChanged: string;

  constructor() {
    this.content = '<p>Old Text</p>';
    
    setTimeout(() => {  
      this.myModelChanged = '<p>Is the way feasible?</p>';
    }, 50);
    
  }
  
  onReady(): void {
    if(this.ckeditor)
    {
      this.content = this.myModelChanged;
      // or
      //this.ckeditor.instance.setData(this.myModelChanged);
    }
  }
}
0reactions
kzimnycommented, Jan 21, 2018

Issue closed due to inactivity

Read more comments on GitHub >

github_iconTop Results From Across the Web

ng2-ckeditor ngModel doesn't update, events not firing
However when I type, the value in ngModel doesn't change, and the change and editorChange events don't fire. The ready event does fire....
Read more >
Current - CKEditor 4 Documentation
The first one is fired only once, when the CKEDITOR global namespace is loaded while the latter is fired right before any instance...
Read more >
angular ck editor - Plunker
Please set the global variable "CKEDITOR_BASEPATH" before creating editor instances. ... d=arguments[h],m;for(m in d)if(!0===b||null==a[m])if(!c||m in ...
Read more >
Angular CKEditor Example with custom directive and ng-ckeditor
<script src="https://cdnjs.cloudflare.com/ajax/libs/ng-ckeditor/0.2.1/ng-ckeditor.min.js"></ ... <textarea ng-model="content" data-ck-editor></textarea>.
Read more >
Useful Methods And Events In CKEditor - C# Corner
Introduction · CKEDITOR.on('instanceReady', function(ev) { · ev.editor.on('paste', function(evt) { · if (evt.data.type == 'html') { · // when paste ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found