@ctrl/ngx-codemirror
TypeScript icon, indicating that this package has built-in type declarations

7.0.0 • Public • Published

ngx-codemirror npm coverage

DEMO: https://ngx-codemirror.vercel.app

Dependencies

Latest version available for each version of Angular

@ctrl/ngx-codemirror Angular Codemirror
1.3.10 6.x 7.x 5
2.2.1 8.x 5
3.1.3 9.x 5
4.1.1 10.x 11.x 5
5.1.1 12.x-14x 5
6.1.0 15.x 5
current >= 16.x 5

An Angular component wrapper for CodeMirror that extends ngModel. Based on JedWatson/react-codemirror

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@5

Use

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

In your NgModule:

import { FormsModule } from '@angular/forms';
import { NgModule } from '@angular/core';
import { CodemirrorModule } from '@ctrl/ngx-codemirror';

  // add to imports:
  imports: [
    BrowserModule,
    FormsModule,
    CodemirrorModule,
    ...
  ]

In your main.ts or at the root of your application, see documentation:

import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/markdown/markdown';

Import the base css file and your theme

@import '~codemirror/lib/codemirror';
@import '~codemirror/theme/material';

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

  • codeMirrorLoaded - called when codeMirror instance is initiated
  • 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
  • drop - called when file(s) are dropped

License

MIT

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
7.0.0
11,337latest

Version History

VersionDownloads (Last 7 Days)Published
7.0.0
11,337
6.1.07,037
6.0.057
5.1.18,609
5.1.02
5.0.1828
5.0.0111
4.1.11,788
4.1.066
4.0.26
4.0.113
4.0.015
3.1.3364
3.1.20
3.1.10
3.1.00
3.0.49
3.0.30
3.0.20
3.0.10
3.0.00
2.2.1542
2.2.032
2.1.12
2.1.03
2.0.013
1.3.10294
1.3.97
1.3.80
1.3.71
1.3.60
1.3.50
1.3.40
1.3.30
1.3.20
1.3.10
1.3.00
1.2.40
1.2.30
1.2.20
1.2.10
1.2.00
1.1.00
1.0.00
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i @ctrl/ngx-codemirror

Weekly Downloads

31,136

Version

7.0.0

License

MIT

Unpacked Size

64.9 kB

Total Files

13

Last publish

Collaborators

  • scttcper