Gathering detailed insights and metrics for @tots/ngx-monaco-editor-v2
Gathering detailed insights and metrics for @tots/ngx-monaco-editor-v2
Gathering detailed insights and metrics for @tots/ngx-monaco-editor-v2
Gathering detailed insights and metrics for @tots/ngx-monaco-editor-v2
Monaco Editor component for Angular 2 and Above
npm install @tots/ngx-monaco-editor-v2
Typescript
Module System
Node Version
NPM Version
TypeScript (86.35%)
JavaScript (11.25%)
HTML (1.18%)
Shell (0.9%)
CSS (0.31%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
96 Stars
136 Commits
38 Forks
4 Watchers
4 Branches
1 Contributors
Updated on Jul 01, 2025
Latest Version
15.0.0
Package Id
@tots/ngx-monaco-editor-v2@15.0.0
Unpacked Size
128.70 kB
Size
21.93 kB
File Count
22
NPM Version
8.19.2
Node Version
18.12.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
3
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
Install from npm repository:
npm install monaco-editor ngx-monaco-editor-v2 --save
Breaking change from v10, is to use monaco-editor next to ngx-monaco-editor-v2 in your package.json file.
For angular version 6 use v6.x.x
npm install ngx-monaco-editor-v2@6.0.0 --save
Add the glob to assets in angular.json
1{ 2 "apps": [ 3 { 4 "assets": [ 5 { "glob": "**/*", "input": "node_modules/monaco-editor", "output": "/assets/monaco/" } 6 ], 7 ... 8 } 9 ... 10 ], 11 ... 12}
For Angular 6 and below, add the glob to assets in .angular-cli.json
schema - projects.[project-name].architect.build
(to make monaco-editor lib available to the app):
1{ 2 "options":{ 3 {"assets": [ 4 { "glob": "**/*", "input": "node_modules/ngx-monaco-editor/assets/monaco", "output": "./assets/monaco/" } 5 6 ], 7 ... 8 } 9 ... 10 }, 11 ... 12}
Include MonacoEditorModule in Main Module and Feature Modules where you want to use the editor component.(eg: app.module.ts):
1import { BrowserModule } from '@angular/platform-browser'; 2import { NgModule } from '@angular/core'; 3import { FormsModule } from '@angular/forms'; 4 5import { AppComponent } from './app.component'; 6import { MonacoEditorModule } from 'ngx-monaco-editor'; 7 8@NgModule({ 9 declarations: [ 10 AppComponent 11 ], 12 imports: [ 13 BrowserModule, 14 FormsModule, 15 MonacoEditorModule.forRoot() // use forRoot() in main app module only. 16 ], 17 providers: [], 18 bootstrap: [AppComponent] 19}) 20export class AppModule { 21}
Create Editor options in component.(eg: app.component.ts)
1import { Component } from '@angular/core'; 2 3@Component({ 4 selector: 'app-root', 5 templateUrl: './app.component.html' 6}) 7export class AppComponent { 8 editorOptions = {theme: 'vs-dark', language: 'javascript'}; 9 code: string= 'function x() {\nconsole.log("Hello world!");\n}'; 10}
Include editor in html with options and ngModel bindings.(eg: app.component.html)
1<ngx-monaco-editor [options]="editorOptions" [(ngModel)]="code"></ngx-monaco-editor>
Include diff-editor in html with options.(eg: app.component.html)
1<ngx-monaco-diff-editor [options]="options" [originalModel]="originalModel" [modifiedModel]="modifiedModel"></ngx-monaco-diff-editor>
1import { Component } from '@angular/core'; 2import { DiffEditorModel } from 'ngx-monaco-editor'; 3 4@Component({ 5 selector: 'app-root', 6 templateUrl: './app.component.html' 7}) 8export class AppComponent { 9 options = { 10 theme: 'vs-dark' 11 }; 12 originalModel: DiffEditorModel = { 13 code: 'heLLo world!', 14 language: 'text/plain' 15 }; 16 17 modifiedModel: DiffEditorModel = { 18 code: 'hello orlando!', 19 language: 'text/plain' 20 }; 21}
To match height of container element add height: 100% and wrap in container
1<div style="height: 500px"> 2 <ngx-monaco-editor style="height: 100%" [options]="editorOptions" [(ngModel)]="code"></ngx-monaco-editor> 3</div>
Add class to editor tag. (eg. class="my-code-editor")
1<ngx-monaco-editor class="my-code-editor" [options]="editorOptions" [(ngModel)]="code"></ngx-monaco-editor>
Add styling in css/scss file:
1.my-code-editor { 2 .editor-container { 3 height: calc(100vh - 100px); 4 } 5}
Set automaticLayout option to adjust editor size dynamically. Recommended when using in modal dialog or tabs where editor is not visible initially.
Output event (onInit) expose editor instance that can be used for performing custom operations on the editor.
1<ngx-monaco-editor [options]="editorOptions" [(ngModel)]="code" (onInit)="onInit($event)"></ngx-monaco-editor>
1export class AppComponent { 2 editorOptions = {theme: 'vs-dark', language: 'javascript'}; 3 code: string= 'function x() {\nconsole.log("Hello world!");\n}'; 4 onInit(editor) { 5 let line = editor.getPosition(); 6 console.log(line); 7 } 8}
forRoot()
method of MonacoEditorModule accepts config of type NgxMonacoEditorConfig
.
1import { NgModule } from '@angular/core'; 2import { FormsModule } from '@angular/forms'; 3import { BrowserModule } from '@angular/platform-browser'; 4 5import { MonacoEditorModule, NgxMonacoEditorConfig } from 'ngx-monaco-editor'; 6import { AppComponent } from './app.component'; 7 8const monacoConfig: NgxMonacoEditorConfig = { 9 baseUrl: 'app-name/assets', // configure base path for monaco editor. Starting with version 8.0.0 it defaults to './assets'. Previous releases default to '/assets' 10 defaultOptions: { scrollBeyondLastLine: false }, // pass default options to be used 11 onMonacoLoad: () => { console.log((<any>window).monaco); } // here monaco object will be available as window.monaco use this function to extend monaco editor functionalities. 12}; 13 14@NgModule({ 15 declarations: [ 16 AppComponent 17 ], 18 imports: [ 19 BrowserModule, 20 FormsModule, 21 MonacoEditorModule.forRoot(monacoConfig) 22 ], 23 providers: [], 24 bootstrap: [AppComponent] 25}) 26export class AppModule { 27}
onMonacoLoad
property of NgxMonacoEditorConfig
can be used to configure JSON default.
1import { NgModule } from '@angular/core'; 2import { FormsModule } from '@angular/forms'; 3import { BrowserModule } from '@angular/platform-browser'; 4 5import { MonacoEditorModule, NgxMonacoEditorConfig } from 'ngx-monaco-editor'; 6import { AppComponent } from './app.component'; 7 8export function onMonacoLoad() { 9 10 console.log((window as any).monaco); 11 12 const uri = monaco.Uri.parse('a://b/foo.json'); 13 monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ 14 validate: true, 15 schemas: [{ 16 uri: 'http://myserver/foo-schema.json', 17 fileMatch: [uri.toString()], 18 schema: { 19 type: 'object', 20 properties: { 21 p1: { 22 enum: ['v1', 'v2'] 23 }, 24 p2: { 25 $ref: 'http://myserver/bar-schema.json' 26 } 27 } 28 } 29 }, { 30 uri: 'http://myserver/bar-schema.json', 31 fileMatch: [uri.toString()], 32 schema: { 33 type: 'object', 34 properties: { 35 q1: { 36 enum: ['x1', 'x2'] 37 } 38 } 39 } 40 }] 41 }); 42 43} 44 45const monacoConfig: NgxMonacoEditorConfig = { 46 baseUrl: 'assets', 47 defaultOptions: { scrollBeyondLastLine: false }, 48 onMonacoLoad 49}; 50 51@NgModule({ 52 declarations: [ 53 AppComponent 54 ], 55 imports: [ 56 BrowserModule, 57 FormsModule, 58 MonacoEditorModule.forRoot(monacoConfig) 59 ], 60 providers: [], 61 bootstrap: [AppComponent] 62}) 63export class AppModule { 64}
Now pass model config of type NgxEditorModel
to Editor Component
1@Component({ 2 selector: 'app-root', 3 template: `<ngx-monaco-editor [options]="options" [model]="model"></ngx-monaco-editor>`, 4 styles: [] 5}) 6export class AppComponent { 7 options = { 8 theme: 'vs-dark' 9 }; 10 11 jsonCode = [ 12 '{', 13 ' "p1": "v3",', 14 ' "p2": false', 15 '}' 16 ].join('\n'); 17 18 model: NgxEditorModel = { 19 value: this.jsonCode, 20 language: 'json', 21 uri: monaco.Uri.parse('a://b/foo.json') 22 }; 23}
Monaco Editor
Monaco Editor Options
MIT © Miroslav Maksimovic
No vulnerabilities found.
No security vulnerabilities found.