froala / angular-froala

Angular.js bindings for Froala WYSIWYG HTML Rich Text Editor.
https://froala.com/wysiwyg-editor
MIT License
306 stars 123 forks source link

Working with multiple instances #153

Closed 6matko closed 6 years ago

6matko commented 6 years ago

I ran into a problem where I need your help.

I have a button that enables Edit mode on/off and I broadcast it: this.$rootScope.$broadcast('editModeChanged', this.editMode); Also I have different inputs across my view that use the same settings/options, for example:

        this.editorOptions = {
            'toolbarButtons': ['bold', 'italic', 'underline', 'strikeThrough', 'subscript', 'superscript', '|', 'fontFamily', 'fontSize', 'color', 'inlineStyle', 'paragraphStyle'],
            'events': {
                'edit.on': function () {
                    console.log('Edit enabled');
                },
                'edit.off': function () {
                    console.log('Edit disabled');
                }
            }
        };

So far I can achieve this by using:

        if (editModeEnabled) {
            this.editorOptions.froalaEditor('edit.on');
        } else {
            this.editorOptions.froalaEditor('edit.off');
        }

But I can manage only the last initialized instance. If I turn off edit mode, last one will behave as it should be, but other inputs will be fully editable which is wrong.

My task is to achieve all input initialization with specific settings/options (for different inputs they may be different) when "Enable edit mode" button is pressed and destroy all instances when this button is pressed again (edit mode turned off). Any ideas on how to achieve this ? Thank you.

stefanneculai commented 6 years ago

@6matko I would recommend using the manual initialization so that you can have full control over the editor instances: https://github.com/froala/angular-froala#manual-instantiation.