Ask questionsChange the language of an existing editor

I am making a directive to help using Monaco Editor in AngularJS 1.X framework. One feature should be updating the language based on the option. But I cannot change the language.

It seems that the type of monacoeditor in my code is ICommonCodeEditor, I tried monacoeditor.updateOptions({ "language": newValues[key] }), it did nothing. I tried monacoeditor.getModel().updateOptions({ "language": newValues[key] }), it did nothing either. I tried also monacoeditor.setModelLanguage(monacoeditor.getModel(), newValues[key]), it gave an error TypeError: monacoeditor.setModelLanguage is not a function.

Note that it is not the problem of the directive, because it works well to change options like lineNumbers.

Could anyone help?


Answer questions Symbolk

Anyone know how to change the language according to code file extension or first line like "#!/usr/bin/env python"?


Related questions

Monarch: How do you add "@keywords" key to "language object"? (undocumented) hot 3
How to get the line count including line wraps hot 2
Error: Cannot find module 'monaco-editor/esm/vs/editor/contrib/gotoSymbol/goToCommands' hot 2
Removing the tooltip on the read-only editor that says 'cannot edit in read-only editor' hot 1
Monaco paste event hot 1
Registering/Providing custom Commands/CodeActions hot 1
Error: Cannot find module 'monaco-editor/esm/vs/editor/contrib/goToDefinition/goToDefinitionCommands' hot 1
TypeScript declaration preview from extra lib results in error hot 1
Editor props/extends the actual width of the parent that is a flexbox item hot 1
Problem with insane.js while using monaco-editor@0.18.0 hot 1
javascript/typescript typedefs lost when webworker times out hot 1
Can't scroll in firefox hot 1
How to add simple custom language support? hot 1
monaco-editor polute the global variables, making incompatible with other JS libraries, such as CodeMirror, RequireJS, SeaJS, etc. hot 1
Highlight merge conflicts in monaco like in VSCode hot 1
Github User Rank List