Skip to content

CodeMirror does not display colors, code, or mode #42

Description

@andrewryan1906

I've tried following the instructions and piecing together stuff on the forums and can't seem to get this to work. I'm running Angular 7.

My angular.json:

          "styles": [
      ..
              "node_modules/codemirror/lib/codemirror.css",
              "node_modules/codemirror/theme/darcula.css"
            ],
            "scripts": [
              "node_modules/codemirror/lib/codemirror.js",
            ]

My feature module:

@NgModule({
 imports: [
..
    CodemirrorModule,
  
  ],
  providers: [..],
  exports: []
})

My component HTML:

<codemirror formControlName="template" [config]="batchTemplateCodeMirrorConfig" style="width: 100%" [ngClass]="form.get('template').errors && form.get('template').touched ? 'is-invalid' : ''"> </codemirror>

My component ts:

import 'codemirror/mode/javascript/javascript';


@Component({
..
})
export class CodeMirrorDemo implements OnInit, OnDestroy {

 ..
  batchTemplateCodeMirrorConfig = {
    value: 'let x=x+1',
    theme: 'darcula.css',
    lineNumbers: true,
    mode: 'javascript' };

..

The line numbers display, but no theming comes through and the javascript mode isn't respected.

What am I missing? FWIW I tried including the javascript mode js in the angular.json, but I got a loading error in the Chrome console:

CodeMirror.defineMode is not a function

.. and it didn't work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions