materiahq / ngx-monaco-editor

Monaco Editor Library for Angular v6 and above
MIT License
159 stars 35 forks source link

Not binding [(ngModel)] cause error #47

Closed guyutongxue closed 3 years ago

guyutongxue commented 3 years ago

I want to use this component like

<ngx-monaco-editor [options]="editorOptions" (init)="editorInit($event)" ></ngx-monaco-editor>

which there is no [(ngModel)] property. I will control the editor's content by directly accessing editor object:

editorInit(editor: monaco.editor.IStandaloneCodeEditor) {
    // get value via editor.getValue();
    // set value via editor.setValue();
    // I will also change editor's model later, so setting ngModel maybe hard for me
}

But this leads to many errors when interacting with editor:

ERROR Error: _this5.onTouched is not a function

TypeError: _this5.onTouched is not a function
    at monaco-editor.component.ts:194
    at l.fire (event.ts:576)
    at H.setValue (codeEditorWidget.ts:1609)
    at codeEditorWidget.ts:1405
    at l.fire (event.ts:576)
    at o._emitOugoingEvents (viewModelEventDispatcher.ts:62)
    at o.emitOutgoingEvent (viewModelEventDispatcher.ts:38)
    at w.setHasFocus (viewModelImpl.ts:179)
    at textAreaHandler.ts:307
    at l.fire (event.ts:576)
    at errors.ts:22
    at ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:28282)
    at ZoneDelegate.invokeTask (zone.js:420)
    at Zone.runTask (zone.js:188)
    at ZoneTask.invokeTask (zone.js:503)
    at ZoneTask.invoke (zone.js:492)
    at timer (zone.js:3034)

So is there any solution to solve this?

guyutongxue commented 3 years ago

I'm stupid; just [ngModel]="editor.getValue()" is OK.