Skip to content

Instantly share code, notes, and snippets.

@1nv1n
Created September 20, 2018 18:34
Show Gist options
  • Save 1nv1n/635d0e261a76f6c1ad4f6e3e220827db to your computer and use it in GitHub Desktop.
Save 1nv1n/635d0e261a76f6c1ad4f6e3e220827db to your computer and use it in GitHub Desktop.
Angular6Monaco
angular.json
...
"assets": [
"src/assets",
...
{ "glob": "**/*", "input": "../node_modules/ngx-monaco-editor/assets/monaco", "output": "./assets/monaco/" }
],
...
app.module.ts
...
import { MonacoEditorModule, NgxMonacoEditorConfig } from 'ngx-monaco-editor';
...
const monacoConfig: NgxMonacoEditorConfig = {
baseUrl: './assets/monaco/',
defaultOptions: { scrollBeyondLastLine: false },
onMonacoLoad: () => { console.log((<any>window).monaco); }
};
...
@NgModule({
imports: [
...
MonacoEditorModule.forRoot(monacoConfig)
],
...
home.component.ts
...
export class HomeComponent implements OnInit {
editorOptions;
code;
constructor(public overlayContainer: OverlayContainer, public electronService: ElectronService) {}
@HostBinding('class') componentCssClass;
ngOnInit() {
this.editorOptions = {theme: 'vs-dark', language: 'javascript'};
this.code = 'function x() {\nconsole.log("Hello world!");\n}';
}
...
home.component.html
...
<ngx-monaco-editor [options]="editorOptions" [(ngModel)]="code"></ngx-monaco-editor>
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment