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
736 stars 202 forks source link

How to pass updated content to other component or Service. #498

Open basavarj opened 2 years ago

basavarj commented 2 years ago

'contentChanged': function () { this.reportContent = this.html.get();
// this.eventEmitterService.froalaContent.next(this.reportContent);
}

I tried to pass updated content in contentChanged event but angular code doesn't work in any of froala events. Please help me

Suneeh commented 9 months ago

I use a custom FroalaComponent for this. It extends MatFormField and ControlValueAccessor and many more.

private _editor: FroalaEditor | null = null;
... initialization stuffs
setValue(value: string | null) {
    this._editor.html.set(value || '');
    this._editor.undo.reset();
    this._editor.undo.saveStep();
}

I would recommend checking if the editor already exists and handle / save the value for later if it doesn't. Also it might be handy to check if the value is the same, as the current content - because then you would not want to reset the undo.