npm i @ngstack/code-editor
app.module.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { CodeEditorModule } from '@ngstack/code-editor'; import { AppComponent } from './app.component'; import { HelloComponent } from './hello.component'; @NgModule({ imports: [ BrowserModule, FormsModule, CodeEditorModule.forRoot() ], declarations: [ AppComponent, HelloComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } |
app.component.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import { Component, Input } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class AppComponent { @Input() activeTheme = 'vs'; @Input() readOnly = false; @Input() code = [ `import { TranslateModule, TranslateService } from '@ngstack/translate';`, `import { CodeEditorModule } from '@ngstack/code-editor';`, `import * as fs from 'fs';`, '', `export class MyClass {`, ` constructor(translate: TranslateService) {`, '', ' }', `}` ].join('\n'); dependencies: string[] = [ '@types/node', '@ngstack/translate', '@ngstack/code-editor' ]; options = { contextmenu: true, minimap: { enabled: true } }; } |
app.component.html
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<h1>@ngstack/code-editor (Angular 6)</h1> <p> The component might need a few seconds to load typings. You should be able to see auto-completion for the imported types. </p> <ngs-code-editor theme="vs-dark" [(value)]="code" language="typescript" [dependencies]="dependencies" [options]="options"> </ngs-code-editor> |
FULL SOURCE CODE