How to Access codemirror text area value in Angular2 Component?

后端 未结 2 634
情书的邮戳
情书的邮戳 2021-01-24 16:13

I am trying to link codemirror with Angular 2 (TypeScript) . Right now ,I am able to display CodeEditor using a codearea custom directive ,which dynamically loads a script file

2条回答
  •  死守一世寂寞
    2021-01-24 16:30

    I use it a little bit differently but maybe it will help you. Basiaclly in ngAfterViewInit I create code mirror instance using elementRef:

    this.cm = CodeMirror(this.elementRef.nativeElement, options);
    

    then in the onChange event:

    this.cm.on('change', (editor: CodeMirror.Editor) => {
      editor.getDoc().getValue();
    });
    

    If you don't want to use onChange, you can always get the value from code mirror instance, eg.

    cmInstance.getEditor().getDoc().getValue()
    

提交回复
热议问题