Skip to content

gorunovanton/ngx-monaco-editor

 
 

Repository files navigation

Documentation

Try it out on : live demo.

Api reference available on : documentation.

Installation

Install from npm repository:

npm install @materia-ui/ngx-monaco-editor --save

Add the glob to assets in angular.json (to make monaco-editor lib available to the app):

{
    ...
    "projects": {
      "YOUR_APP_NAME": {
          ...
          "architect": {
              "build": {
                ...
                "options": {
                    ...
                    "assets": [
                        { "glob": "**/*", "input": "node_modules/monaco-editor", "output": "assets/monaco-editor/" }
                    ],
                    ...
                }
                ...
              }
            }
            ...
        }
    },
    ...
}

Sample

Include MonacoEditorModule in Main Module and Feature Modules where you want to use the editor component.(eg: app.module.ts):

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';
import { MonacoEditorModule } from '@materia-ui/ngx-monaco-editor';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    MonacoEditorModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {
}

Create Editor options in component.(eg: app.component.ts)

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent {
  editorOptions = {theme: 'vs-dark', language: 'javascript'};
  code: string = 'function x() {\nconsole.log("Hello world!");\n}';
  originalCode: string = 'function x() { // TODO }';
}

Include editor component in your html with options input and ngModel bindings (eg: app.component.html) or using ReactiveForm features.

<ngx-monaco-editor [options]="editorOptions" [(ngModel)]="code"></ngx-monaco-editor>

Include diff-editor component in your html and use the following inputs: options, original and modified (eg: app.component.html).

<ngx-monaco-diff-editor [options]="editorOptions" [original]="originalCode" [modified]="code"></ngx-monaco-diff-editor>

Both components support all available monaco-editor options:

Motivations

We wanted to use monaco-editor library with angular in our desktop application: Materia Designer.

The current angular libraries did not cover all of our needs, notably:

  • Works on Browser and Electron application,
  • Support flex-box container and correctly resize editor when container size changes.

About

Monaco Editor Library for Angular v6 and above

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 74.8%
  • HTML 11.4%
  • JavaScript 8.5%
  • CSS 5.3%