ngx-monaco-editor
ngx-monaco-editor copied to clipboard
How can I format my json on init ? getAction(id).run is not work
getAction(id)
the api is not work
this is supported actions.There is no foramt
You have two ways to do this:
-
In init, you can pass your JSON object to JSON.stringify method and set the indentation. Ex:
const jsonObj= { key: value }; const content = JSON.stringify(jsonObj, undefined, 4);
Set this content on editor. You will see your content formatted. -
Trigger following command:
editor.trigger('format', 'editor.action.format');
@viccsjain Thank you!!
@viccsjain The first way is ok~ But the second way is not work
editor.trigger('format', 'editor.action.format');
the editor.trigger('format', 'editor.action.format'); not work
I'm having the same issue. Neither solution works for me
onEditorInit(editor) { editor.trigger('format', 'editor.action.format'); }
Or
onEditorInit(editor) { const format = editor.getAction('editor.action.format'); format.run(); }
Changing the command to 'editor.action.formatDocument'
works for me. See item 32 in the image of the supported actions.