Как правильно подключить библиотеку Codemirror к Angular 5? - PullRequest
0 голосов
/ 24 мая 2018

Документация здесь http://codemirror.net А для Angular https://www.npmjs.com/package/ng2-codemirror Установлено 1) npm install ng2-codemirror 2) npm install codemirror 3) В app.module.ts

import { CodemirrorModule } from 'ng2-codemirror';
@NgModule({
  // ...
  imports:      [
    CodemirrorModule
  ],
  // ...
})

4) В .angular-cli.json

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

5) Вместо textarea пишет

<codemirror
  *ngIf="chaptersService.currentChapter" 
  [(ngModel)]="chaptersService.currentChapter.novel"
  [config]="{lineNumbers: true}"
  autofocus
  (keyup)="markAsEdited()"
  #textareaNovel>
</codemirror>

Классы применяются из Codemirror, но я не могу ввести текст.Что я делаю не так?

1 Ответ

0 голосов
/ 01 июня 2018

Пожалуйста, переместите ng-if в div выше, не используйте тег, используйте [autofocus] = true и удалите последний #

 <div *ngIf="chaptersService.currentChapter">
    <codemirror 
      [(ngModel)]="chaptersService.currentChapter.novel"
      [config]="{lineNumbers: true}"
      [autofocus]=true
      (keyup)="markAsEdited()">
    </codemirror>
</div>
...