An Angular component wrapper for CodeMirror that extends ngModel
Based on:
https://github.com/JedWatson/react-codemirror - This project is mostly a port of react-codemirror
https://github.com/chymz/ng2-codemirror - Good to reference
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.
import { CodemirrorModule } from '@ctrl/ngx-codemirror';
import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/markdown/markdown';
Import the css files
@import "~codemirror/lib/codemirror.css";
@import "~codemirror/theme/material.css";
Use The Component
<ngx-codemirror
[(ngModel)]="this.defaults[this.mode]"
[options]="{
lineNumbers: true,
mode: 'markdown',
}"
></ngx-codemirror>
Inputs
All Inputs of ngModel
options
- options passed to the CodeMirror instance see http://codemirror.net/doc/manual.html#configname
- name applied to the created textareaautoFocus
- setting applied to the created textareapreserveScrollPosition
- preserve previous scroll position after updating value
Outputs
All outputs of ngModel
focusChange
- called when the editor is focused or loses focusscroll
- called when the editor is scrolledcursorActivity
- called when the text cursor is moved
License
MIT