Skip to content

@memberjunction/ng-code-editor

A flexible Angular code editor component built on CodeMirror 6, with syntax highlighting for 150+ languages, Angular forms integration, and extensive customization options.

The @memberjunction/ng-code-editor package wraps CodeMirror 6 in an Angular component with full support for ngModel, formControlName, and ControlValueAccessor. It provides syntax highlighting, line wrapping, whitespace visualization, configurable indentation, and runtime language switching — all reactive to input property changes.

graph TD
    A[CodeEditorModule] --> B[CodeEditorComponent]
    A --> C[ToolbarConfig]

    B --> D["CodeMirror 6 EditorView"]

    D --> E["Language Support
    (150+ languages)"]
    D --> F["Form Integration
    (ngModel / formControl)"]
    D --> G["Extensions
    (themes, keymaps, custom)"]

    B --> H["Setup Modes"]
    H --> H1["basic (full features)"]
    H --> H2["minimal (lightweight)"]
    H --> H3["null (custom only)"]

    style A fill:#2d6a9f,stroke:#1a4971,color:#fff
    style B fill:#7c5295,stroke:#563a6b,color:#fff
    style D fill:#2d8659,stroke:#1a5c3a,color:#fff
    style H fill:#b8762f,stroke:#8a5722,color:#fff
Terminal window
npm install @memberjunction/ng-code-editor
import { CodeEditorModule } from '@memberjunction/ng-code-editor';
@NgModule({
imports: [CodeEditorModule]
})
export class AppModule { }
<mj-code-editor
[value]="code"
[language]="'javascript'"
[placeholder]="'// Enter your code here...'"
(change)="onCodeChange($event)">
</mj-code-editor>
<mj-code-editor
[(ngModel)]="code"
[languages]="languages"
[language]="'typescript'"
[lineWrapping]="true"
[indentWithTab]="true">
</mj-code-editor>
import { languages } from '@codemirror/language-data';
export class MyComponent {
code = '';
languages = languages;
}
<form [formGroup]="form">
<mj-code-editor
formControlName="query"
[languages]="languages"
[language]="'sql'"
[placeholder]="'SELECT * FROM ...'"
[setup]="'basic'">
</mj-code-editor>
</form>

mj-code-editor

InputTypeDefaultDescription
valuestring''The editor’s content
disabledbooleanfalseDisables the editor
readonlybooleanfalseMakes the editor read-only
placeholderstring''Placeholder text when empty
indentWithTabbooleanfalseTab key indents instead of focusing next element
indentUnitstring''Indentation string (e.g., ' ' for 2 spaces)
lineWrappingbooleanfalseWrap long lines
highlightWhitespacebooleanfalseVisualize whitespace characters
languagesLanguageDescription[][]Available language descriptions (static)
languagestring''Current language for syntax highlighting
setup'basic' | 'minimal' | null'basic'Built-in editor setup
extensionsExtension[][]Additional CodeMirror extensions
autoFocusbooleanfalseFocus editor on init (static)
rootDocument | ShadowRootundefinedCustom root for the editor (static)
OutputTypeDescription
changeEventEmitter<string>Content changed
focusEventEmitter<void>Editor gained focus
blurEventEmitter<void>Editor lost focus
PropertyTypeDescription
viewEditorView | undefinedUnderlying CodeMirror EditorView instance
  • 'basic' (default): Full setup with line numbers, fold gutters, search, bracket matching
  • 'minimal': Undo/redo history and basic keymaps only
  • null: No built-in setup; complete customization via extensions
PackageDescription
@memberjunction/coreCore framework
@memberjunction/core-entitiesEntity definitions
@memberjunction/globalGlobal utilities
@memberjunction/ng-container-directivesContainer directives
codemirrorCodeMirror 6 core
@codemirror/lang-javascriptJavaScript/TypeScript language
@codemirror/lang-jsonJSON language
@codemirror/lang-pythonPython language
@codemirror/lang-sqlSQL language
@codemirror/language-data150+ language definitions
@codemirror/mergeMerge/diff extensions
  • @angular/common ^21.x
  • @angular/core ^21.x
Terminal window
cd packages/Angular/Generic/code-editor
npm run build

ISC