{"id":20778983,"url":"https://github.com/courage007/angular-monaco-editor","last_synced_at":"2025-04-30T19:41:09.801Z","repository":{"id":57178784,"uuid":"148114910","full_name":"courage007/Angular-Monaco-Editor","owner":"courage007","description":"An Angular Code Editor component based on the MS Monaco Code Editor  ","archived":false,"fork":false,"pushed_at":"2019-12-27T13:36:19.000Z","size":4710,"stargazers_count":4,"open_issues_count":4,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-30T08:52:00.091Z","etag":null,"topics":["angular","angular-code-editor","angular2","code-editor","monaco-code-editor","ngx-code-editor"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/courage007.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-10T07:17:32.000Z","updated_at":"2020-11-17T01:32:54.000Z","dependencies_parsed_at":"2022-09-09T19:00:28.183Z","dependency_job_id":null,"html_url":"https://github.com/courage007/Angular-Monaco-Editor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courage007%2FAngular-Monaco-Editor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courage007%2FAngular-Monaco-Editor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courage007%2FAngular-Monaco-Editor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courage007%2FAngular-Monaco-Editor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/courage007","download_url":"https://codeload.github.com/courage007/Angular-Monaco-Editor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251770930,"owners_count":21641176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","angular-code-editor","angular2","code-editor","monaco-code-editor","ngx-code-editor"],"created_at":"2024-11-17T13:25:23.537Z","updated_at":"2025-04-30T19:41:09.778Z","avatar_url":"https://github.com/courage007.png","language":"TypeScript","readme":"# Monaco Editor Component for Angular 2+\n\nUsing this Module you can utilize the Monaco Editor as an Angular Component. Feel free to contribute, raise feature requests and make it better.\n\nSupports all the options available in monaco-editor [Monaco Editor Options](https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.ieditorconstructionoptions.html)\n\n## Setup\n\n### Installation\n\n- (1) Install from npm repository:\n```\nnpm install monaco-editor --save\n\nnpm install angular-monaco-editor --save\n ```\n \n- (2) Add the glob to assets in **.angular-cli.json** (to make monaco-editor lib available to the app):\n```typescript\n{\n  \"apps\": [\n    {\n      \"assets\": [\n        { \n          \"glob\": \"**/*\", \n          \"input\": \"../node_modules/monaco-editor/min\", \n          \"output\": \"./assets/monaco/\" \n        }\n      ],\n      ...\n    }\n    ...\n  ],\n  ...\n}\n ```\n PS: In Angular 6 CLI, please copy node_modules/monaco-editor/min to src/assets and rename folder as 'monaco' by hand.  \n PPS: Angular 6 CLI does not allow to dymanicly load resource using input/output.\n\n### Sample\n- (1) Include AngularMonacoEditorModule in Main Module and Feature Modules where you want to use the editor component.(eg: app.module.ts): \n```typescript\nimport { BrowserModule } from '@angular/platform-browser';\nimport { NgModule } from '@angular/core';\nimport { FormsModule } from '@angular/forms';  //import FormsModule to make ngModel attr work\n\nimport { AngularMonacoEditorConfig, AngularMonacoEditorModule } from 'angular-monaco-editor';\n\nimport { AppComponent } from './app.component';\n\n@NgModule({\n  declarations: [\n    AppComponent\n  ],\n  imports: [\n    FormsModule, // Warning: depended module, must be imported\n    BrowserModule,\n    AngularMonacoEditorModule.forRoot()\n  ],\n  providers: [],\n  bootstrap: [AppComponent]\n})\nexport class AppModule { }\n```\nPS: Please make sure the **'FormsModule'** also be imported when importing the AngularMonacoEditorModule.\n\n- (2) Create Editor options in component.(eg: app.component.ts)\n```typescript\nimport { Component } from '@angular/core';\n\n@Component({\n  selector: 'app-root',\n  templateUrl: './app.component.html',\n  styleUrls: ['./app.component.css']\n})\n\nexport class AppComponent {\n  options = {\n    theme: 'vs-dark',\n    language: 'javascript',\n  };\n \n  code: string = `\n    function foo() {\n      alert('Hello');\n      alert('World');\n      alert('Hello World.');\n    }`;\n}\n```\n- (3) Include editor in html with options and ngModel bindings.(eg: app.component.html)\n```html\n\u003cangular-monaco-editor class=\"customMonacoEditor\" [options]=\"options\" [(ngModel)]=\"code\"\u003e \u003c/angular-monaco-editor\u003e\n```\n\n### Styling\n- (1) Add class to editor tag. (eg. class=\"editorPanel\")\n```html\n\u003cdiv class=\"editorPanel\"\u003e\n    \u003cangular-monaco-editor class=\"customMonacoEditor\" [options]=\"options\" [(ngModel)]=\"code\"\u003e\u003c/angular-monaco-editor\u003e\n\u003c/div\u003e\n```\n- (2) Add styling in css/scss file:\n```css\n.editorPanel{\n    display: block;\n    position: absolute;\n    top: 0px;\n    bottom: 0px;\n    left: 0px;\n    right: 0px;\n}\n.editorPanel .customMonacoEditor { /*set automaticLayout*/\n    height: calc(100vh - 0px);\n}\n```\nSet automaticLayout option to adjust editor size dynamically. Recommended when using in modal dialog or tabs where editor is not visible initially.\n\n### Events\nOutput event (onInit) expose editor instance that can be used for performing custom operations on the editor. \n```html\n\u003cangular-monaco-editor class=\"customMonacoEditor\" [options]=\"options\" [(ngModel)]=\"code\" (onInit)=\"onInitHandler($event)\"\u003e\u003c/angular-monaco-editor\u003e\n```\n\n```typescript\n\nexport class AppComponent {\n  options = {theme: 'vs-dark',language: 'javascript'};\n  code: string = `\n    function foo() {\n      alert('Hello');\n      alert('World');\n      alert('Hello World.');\n  `;\n  \n  // Add Event Handler\n  onInitHandler(event: any){\n    console.log(event);\n  }\n\n}\n```\n\n## Configurations\n`forRoot()` method of AngularMonacoEditorModule accepts config of type `AngularMonacoEditorConfig`.\n```typescript\nimport { NgModule } from '@angular/core';\nimport { FormsModule } from '@angular/forms';\nimport { BrowserModule } from '@angular/platform-browser';\n\nimport { AngularMonacoEditorModule, AngularMonacoEditorConfig } from 'angular-monaco-editor';\nimport { AppComponent } from './app.component';\n\nconst monacoConfig: AngularMonacoEditorConfig = {\n  baseUrl: 'app-name/assets', // configure base path for monaco editor\n  defaultOptions: { scrollBeyondLastLine: false }, // pass default options to be used\n  onMonacoLoad: () =\u003e { console.log((\u003cany\u003ewindow).monaco); } // here monaco object will be available as window.monaco use this function to extend monaco editor functionality.\n};\n\n@NgModule({\n  declarations: [\n    AppComponent\n  ],\n  imports: [\n    BrowserModule,\n    FormsModule,\n    AngularMonacoEditorModule.forRoot(monacoConfig)\n  ],\n  providers: [],\n  bootstrap: [AppComponent]\n})\nexport class AppModule {\n}\n```\n\n### Configure JSON Defaults\n`onMonacoLoad` property of `AngularMonacoEditorConfig` can be used to configure JSON default.\n```typescript\nimport { BrowserModule } from '@angular/platform-browser';\nimport { NgModule } from '@angular/core';\nimport { FormsModule } from '@angular/forms';  //import FormsModule to make ngModel attr work\n\nimport * as monaco from 'monaco-editor';\nimport { AngularMonacoEditorConfig, AngularMonacoEditorModule } from 'angular-monaco-editor';\n\nimport { AppComponent } from './app.component';\n\nconst monacoConfig: AngularMonacoEditorConfig = {\n  baseUrl: 'assets',\n  defaultOptions: { scrollBeyondLastLine: false },\n  onMonacoLoad: () =\u003e {\n    // console.log(\"moncaco: \" + (\u003cany\u003ewindow).monaco);\n\n    const id = \"foo.json\";\n    monaco.languages.json.jsonDefaults.setDiagnosticsOptions({\n      validate: true,\n      schemas: [{\n        uri: \"http://myserver/foo-schema.json\",\n        fileMatch: [id],\n        schema: {\n          type: \"object\",\n          properties: {\n            p1: {\n              enum: [ \"v1\", \"v2\"]\n            },\n            p2: {\n              $ref: \"http://myserver/bar-schema.json\"\n            }\n          }\n        }\n      }]\n    });\n\n  }\n};\n\n@NgModule({\n  declarations: [\n    AppComponent\n  ],\n  imports: [\n    FormsModule,\n    BrowserModule,\n    AngularMonacoEditorModule.forRoot(monacoConfig)\n  ],\n  providers: [],\n  bootstrap: [AppComponent]\n})\nexport class AppModule { }\n```\n\n## Links\n[Monaco Editor](https://github.com/Microsoft/monaco-editor/)\u003cbr/\u003e\n\n## License\n\nMIT © [John Wang](https://github.com/courage007)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcourage007%2Fangular-monaco-editor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcourage007%2Fangular-monaco-editor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcourage007%2Fangular-monaco-editor/lists"}