Monaco Editor Component for Angular 2 and above.
Using this Module you can utilize the Monaco Editor as an Angular Component. Feel free to contribute, raise feature requests and make it better.
Supports all the options available in monaco-editor Monaco Editor Options
Setup
Installation
Install from npm repository:
npm install ngx-editor-monaco --save
Add the glob to assets in .angular-cli.json (to make monaco-editor lib available to the app):
Sample
Include MonacoEditorModule in Main Module and Feature Modules where you want to use the editor component.(eg: app.module.ts):
;; ;;
Create Editor options in component.(eg: app.component.ts)
;
Include editor in html with options and ngModel bindings.(eg: app.component.html)
Include diff-editor in html with options and property binding of previousCode and currentCode
ex) previousCode = { code: ` `(function(jit_createRendererType2_0,jit_viewDef_1,jit_textDef_2,jit_elementDef_3,jit_View_EditorComponent_0_4,jit__object_Object__5,jit_providerDef_6,jit_InjectionToken_NgValueAccessor_7,jit_EditorComponent_8,jit_directiveDef_9,jit_NgZone_10 /*\`\`*/) { var styles_AppComponent = []; var RenderType_AppComponent = jit_createRendererType2_0({encapsulation:2,styles:styles_AppComponent, data:{}}); function View_AppComponent_0(_l) { return jit_viewDef_1(0,[(_l()(),jit_textDef_2(null,['\\n '])),(_l()(),jit_elementDef_3(0, null,null,1,'h1',[],null,null,null,null,null)),(_l()(),jit_textDef_2(null,['\\n Welcome to ', '!!\\n '])),(_l()(),jit_textDef_2(null,['\\n '])),(_l()(),jit_elementDef_3(0, null,null,2,'ngx-editor-monaco',[['flex',''],['language','javascript'],['style', 'height: 200px'],['theme','vs-dark']],null,null,null,jit_View_EditorComponent_0_4, jit__object_Object__5)),jit_providerDef_6(5120,null,jit_InjectionToken_NgValueAccessor_7 `, language: 'javascript' } currentCode = { code: '', language: 'javascript' }
Styling
Add class to editor tag. (eg. class="my-code-editor")
Add styling in css/scss file:
.my-code-editor
Set automaticLayout option to adjust editor size dynamically. Recommended when using in modal dialog or tabs where editor is not visible initially.
Events
Output event (onInit) expose editor instance that can be used for performing custom operations on the editor.
Configurations
forRoot()
method of MonacoEditorModule accepts config of type NgxMonacoEditorConfig
.
;;; ;; ;