我正在尝试使用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>"
}
}