jodit / jodit-angular

Angular wrapper for Jodit && Hey. Due to the fact that I do not use Angular in my projects, I cannot fix plugin errors in a timely manner. If you want the plugin to develop, send PR or better become a contributor
MIT License
48 stars 35 forks source link

Toggling the theme does not update the editor theme without refreshing the page #16

Open jaredmahan opened 5 years ago

jaredmahan commented 5 years ago

I have a theme toggle (from light to dark) on the page and it does not update the theme option unless I refresh the page and the editor is initialized with the theme value.

jaredmahan commented 5 years ago

After further digging, I found that this is not an issue of the angular plugin but rather of the editor itself, changing the template option in the editor does not take effect until the editor is destroyed and recreated. Below is the code changes I made, but I am hoping there is a better way to accomplish this rather than redrawing the entire component as it is not the most performant solution. ngOnChanges(changes: SimpleChanges) { const config: SimpleChange = changes.config; if ( !!config && !!config.currentValue && config.previousValue && config.currentValue.theme !== config.previousValue.theme ) { let value = ''; if (!!this.editor.value) value = this.editor.value; this.editor.destruct(); this.editor = new Jodit(this.element, this.config); this.editor.value = value; } }