atularen / ngx-monaco-editor

Monaco Editor component for Angular 2 and Above
https://www.npmjs.com/package/ngx-monaco-editor
MIT License
428 stars 155 forks source link

Create tabs; calling `createModel({...})` #136

Open dnmd opened 5 years ago

dnmd commented 5 years ago

As per instructions from the monaco editor repo, the preferred method of creating tabs is;

for each model, you can save its view state (cursor, scroll position, etc) via -

But I get stuck at the second step, as I am not able to create multiple instance. Am I missing something or is this simply not implemented (yet)? Thanks in advance

ramseyfeng commented 4 years ago

Did you solve the issue? I have same question like you got. Calling createModel is not available.

dnmd commented 4 years ago

No I haven't...

ramseyfeng commented 4 years ago

@dnmd You can wait until monaco editor is loaded, and use below way to create the model:

monaco.editor.createModel(model.value, model.language, uri)

EnderCommunity commented 4 years ago

No, it's not working.

thmang82 commented 4 years ago

Also not working for me. Got the editor instance via (onInit)="editorInitialized($event)". Here is the code from the ts file of the component:

import * as monaco from 'monaco-editor';
...
editorInitialized(editor) {
        let model = monaco.editor.createModel("Hello");
        editor.setModel(model)
}

But the editor simply gets blank when loaded. Maybe the global editor "scope" of the monaco.editor.createModel call and the scope of the monaco.editor.IStandaloneCodeEditor instance from ngx-monaco-editor is different? Can somebody help?

thmang82 commented 4 years ago

Turns out, it works when using the monaco instance that ngx-monaco-editor loads internally:

...
editorInitialized(editor) {
    let monaco = window.monaco;
    let model = monaco.editor.createModel("Hello");
    editor.setModel(model)
}