Closed datavisorfrankhe closed 5 years ago
Yes you can do it by modifying the options
input and changing its reference (because our monaco components have an OnPush change detection strategy).
Here is an example :
component.html
<ngx-monaco-editor [options]="editorOptions" [(ngModel)]="code"></ngx-monaco-editor>
component.ts
editorOptions = {theme: 'vs-dark', language: 'javascript'};
....
changeTheme(theme: string) {
this.editorOptions = { ...this.editorOptions, theme: theme }; // Or Object.assign({}, this.editorOptions, {theme: theme});
}
Thanks it worked. But Object.assign is not triggering the updates
Glad it works! Object.assign()
should works too, I am using this method in the live demo.
I use Object.assign() but it removes all decorations and selections. If that's not what you want, try monaco.editor.setModelLanguage()
and monaco.editor.setTheme()
I need to dynamically change the editor theme, are there any method I can call to change it dynamically? Thanks