ngx-monaco-editor
ngx-monaco-editor copied to clipboard
ngx-monaco-editor component requires options unnecessarily
Thanks to your handy defaultOptions
feature, I can ensure consistency in the presentation of the monaco editor throughout my app without specifying options. However, whenever I remove "options" from component implementation, e.g.
<ngx-monaco-editor [model]="model"></ngx-monaco-editor>
I get the exception:
TypeError: Cannot set property 'model' of undefined
at EditorComponent.set [as model] (editor.component.js:42)
at updateProp (core.js:12619)
at checkAndUpdateDirectiveInline (core.js:12326)
at checkAndUpdateNodeInline (core.js:13893)
at checkAndUpdateNode (core.js:13836)
at debugCheckAndUpdateNode (core.js:14729)
at debugCheckDirectivesFn (core.js:14670)
at Object.eval [as updateDirectives] (EditContentComponent.html:37)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:14655)
at checkAndUpdateView (core.js:13802)
Which points to this line in editor.component:
this.options.model = model;
As a result, I am forced to use the editor component as follows:
<ngx-monaco-editor [options]="{}" [model]="model"></ngx-monaco-editor>
It doesn't make sense to me that I would need to specify options. It seems like the responsibility of the component to provide a default if one is not provided, especially since the module essentially makes this directive unnecessary.
Thanks for what you've done here! I appreciate it!
To help people who have the same problem as us, it is also important to respect the order. options
must be declared before model
in the HTML tag, otherwise options will still be undefined
when the model will be set.
Adding the following to the BaseEditor constructor resolves the issue for me. (PR submitted.)
this._options = Object.assign({}, this.config.defaultOptions)