Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngx-monaco-editor component requires options unnecessarily #59

Open
ericp96 opened this issue May 30, 2018 · 2 comments · May be fixed by #249
Open

ngx-monaco-editor component requires options unnecessarily #59

ericp96 opened this issue May 30, 2018 · 2 comments · May be fixed by #249

Comments

@ericp96
Copy link

ericp96 commented May 30, 2018

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!

@JimmyTournemaine
Copy link

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.

@trevorhreed
Copy link

Adding the following to the BaseEditor constructor resolves the issue for me. (PR submitted.)

this._options = Object.assign({}, this.config.defaultOptions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants