froala / angular-froala-wysiwyg

Angular 4, 5, 6, 7, 8 and 9 plugin for Froala WYSIWYG HTML Rich Text Editor.
https://froala.com/wysiwyg-editor
731 stars 201 forks source link

froala editor stopped working as component in angular #338

Open dolphinsd opened 5 years ago

dolphinsd commented 5 years ago

Here is example,if editor is used in component it does not work. https://stackblitz.com/edit/angular-froala-v3-custombutton-kwrlth 

test should be inside both editors

please fix ASAP we think it s because of use if ngZone.https://angular.io/api/core/NgZone it should not be used to update ui   

dolphinsd commented 5 years ago

we found a fix that needs to be applied to directive:

// fix setHtml ` private setHtml() { if (this._hasSpecialTag) { this._editor.html.set(this._model || ""); } else { this._editor.html.set(this._oldModel || ""); }

// This will reset the undo stack everytime the model changes externally. Can we fix this?
this._editor.undo.reset();
this._editor.undo.saveStep();

}`

// fix set content private setContent(firstTime = false) { let self = this;

// Set initial content
if (this._model || this._model == '') {
  this._oldModel = this._model;
}
if (this._hasSpecialTag) {

  let tags: Object = this._model;

  // add tags on element
  if (tags) {

    for (let attr in tags) {
      if (tags.hasOwnProperty(attr) && attr != this.INNER_HTML_ATTR) {
        this._element.setAttribute(attr, tags[attr]);
      }
    }

    if (tags.hasOwnProperty(this.INNER_HTML_ATTR)) {
      this._element.innerHTML = tags[this.INNER_HTML_ATTR];
    }
  }
} else {
  if (firstTime) {
    this.registerEvent('initialized', function () {
      self.setHtml();
    });
  } else {
    self.setHtml();
  }
}

}

headswe commented 5 years ago

Hey, i was having some really interesting issues in regarding ngIf editors not updating the models after being shown once.

And this fix solved the issue.

headswe commented 5 years ago

To further build upon this, the problem was linked to a editor that would be hidden and shown again with a ngIf inside one component, it works fine it the component itself is ngIf.

I assume there some kind of garbage collecting there that screws it over.