SamVerschueren / ngx-monaco

Monaco Editor for Angular
MIT License
39 stars 20 forks source link

do you support ngModel I get Error: No value accessor for form control with name: 'modelstring' #8

Closed moorthi07 closed 6 years ago

moorthi07 commented 6 years ago

Editor is not displaying. (it appears a tiny pixels in a corner of my container). Even though the style seemed to be applied. (here is the style from console) monaco-editor[_ngcontent-c18] { height: 500px; }

I get this error: Error: No value accessor for form control with name: 'modelstring' for, <monaco-editor required [(ngModel)] ="Entity.modelstring" name="modelstring" [mode]="'json'" [theme]="'clouds'" [options]="options" [readOnly]="false" >

And below is a working ng-ace editor , <ace-editor required [(text)] ="Entity.modelstring" name="modelstring" [mode]="'json'" [theme]="'clouds'" [options]="options" [readOnly]="false"
(change)="onChange()" style="display:block; height: 80vh; width:100%">

SamVerschueren commented 6 years ago

Please read the docs. This is not a drop in replacement with the Ace editor. We don't expose ngModel. You have to bind to file.

moorthi07 commented 6 years ago

Ok. Its not the standard. But, still not working with error 'File' is not exported in ngx-monaco!

SamVerschueren commented 6 years ago

Oh sorry, has to be MonacoFile.

moorthi07 commented 6 years ago

{ uri: string; language: string; content: string; }' is not assignable to type 'File'. Object literal may only specify known properties, and 'uri' does not exist in type 'File'.

moorthi07 commented 6 years ago

'File' is cross referencing some other api. I suggest use the monaco standard that would also be easy for one to quickly try

moorthi07 commented 6 years ago

interface File var File: { Is this right definition for FILE?
new (parts: (string | Blob | ArrayBuffer | ArrayBufferView)[], filename: string, properties?: FilePropertyBag): File; prototype: File; }

moorthi07 commented 6 years ago

Ok, now I tried , file: MonacoFile = { uri: 'index.js', language: 'javascript', content:console.log('hello world');` };

onFileChange(file: MonacoFile) {
    // Handle file change
}`

throws this error, this is dragging tooooooooooo long. 👎 GET http://localhost:4200/libs/vs/loader.js net::ERR_ABORTED

SamVerschueren commented 6 years ago

Take the time to read the docs. You probably forgot to add this entry to .angular-cli.json https://github.com/SamVerschueren/ngx-monaco#angular-clijson

moorthi07 commented 6 years ago

NOpe. I did add. Otherwise it will break right there. Anyways, I even tried moving output to "output": "./assets/monaco/", not working

SamVerschueren commented 6 years ago

Did you install monaco-editor? Not just ngx-monaco?

moorthi07 commented 6 years ago

"monaco-editor": "^0.10.1",

SamVerschueren commented 6 years ago

Output has to be libs/vs, otherwise it will fail to bootstrap Monaco. Can you verify if you actually have something in your libs folder?

moorthi07 commented 6 years ago

ok. I reinstalled both and it seems the style is not picking. So put the style in the directive , that shows the editor now.
<monaco-editor theme="vs-light" [file]="file" (fileChange)="onFileChange($event)" style="display:block; height: 80vh; width:100%"> </monaco-editor>

moorthi07 commented 6 years ago

But do you support bi directional binding? instead of me updating every time onChange?

moorthi07 commented 6 years ago

This is kind of redundant to do. onFileChange(infile: MonacoFile) { this.file.content= infile.content; console.log(' this.file.content', infile.content); }

moorthi07 commented 6 years ago

Great. bi directional binding works as well. Thanks for the help. <monaco-editor theme="vs-light" [(file)]="file" (fileChange)="onFileChange($event)" style="display:block; height: 80vh; width:100%">

SamVerschueren commented 6 years ago

Yes that works, but I'm not a big fan of two-way databinding.

Style should work inside a css file if you set display: block.