以角度获取Codemirror文本区域的值

时间:2017-11-02 12:26:35

标签: angular codemirror

我正在尝试使用angular2来集成codemirror。编辑器正在正确播放,如何在按钮点击时获得编辑器值?我是棱角分明的新人。

app.component.html

<codemirror [(ngModel)]="code" [config]="config"></codemirror>
<div [innerHTML]="code"></div>
<button type="button" name="run_test" class="btn btn-danger" 
(click)="runTest()">Run tests</button>

app.component.ts

@Component({     
  selector: 'app-selector',
  templateUrl: './app.component.html'
})
export class CourseComponent implements OnInit {
code: string;
codeConfig = {
                mode: 'htmlmixed',
                lineWrapping: false,
                lineNumbers: true,   
                gutters: ["CodeMirror-lint-markers"],
                lint: true
             };
      ngOnInit() {
          this.code= "<h1>Hello</h1>";
      }

    runTest()
   {
      //how to get value here
      //console.log(this.code) gives "<h1>Hello</h1>"
   }
}

0 个答案:

没有答案