Skip to content

szabo-tamas-intland/ngx-codemirror

 
 

Repository files navigation

ngx-codemirror


npm travis codecov

DEMO: https://typectrl.github.io/ngx-codemirror/

An Angular component wrapper for CodeMirror that extends ngModel

Based on:

JedWatson/react-codemirror - This project is mostly a port of react-codemirror
chymz/ng2-codemirror - Good to reference

Used in:

tsquery playground: https://tsquery-playground.firebaseapp.com/

Install

codemirror is a peer dependency and must also be installed

npm install @ctrl/ngx-codemirror codemirror

Use

Import CodemirrorModule and bring in the codemirror files for parsing the langague you wish to use.

// Added to NgModule
import { CodemirrorModule } from '@ctrl/ngx-codemirror';

// Import your required language in main.ts or at the root of your application
// see https://codemirror.net/mode/index.html
import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/markdown/markdown';

Import the base css file and your theme

@import "~codemirror/lib/codemirror.css";
@import "~codemirror/theme/material.css";

Use The Component

<ngx-codemirror 
  [(ngModel)]="content" 
  [options]="{
    lineNumbers: true,
    theme: 'material',
    mode: 'markdown'
  }"
></ngx-codemirror>

Inputs

All Inputs of ngModel and

  • options - options passed to the CodeMirror instance see http://codemirror.net/doc/manual.html#config
  • name - name applied to the created textarea
  • autoFocus - setting applied to the created textarea
  • preserveScrollPosition - preserve previous scroll position after updating value

Outputs

All outputs of ngModel and

  • focusChange - called when the editor is focused or loses focus
  • scroll - called when the editor is scrolled (not wrapped inside angular change detection must manually trigger change detection or run inside ngzone)
  • cursorActivity - called when the text cursor is moved

License

MIT


GitHub @scttcper  ·  Twitter @scttcper

About

Codemirror Wrapper for Angular

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 73.9%
  • HTML 11.3%
  • CSS 8.9%
  • JavaScript 5.9%