在Angular2应用程序(TS)中使用CodeMirror。
我有这段代码<codemirror #editor />
,它让我可以轻松访问ElementRef:
@ViewChild('editor') editor: any;
但是,CodeMirror实例本身在this.editor.instance
处更深,所以我使用:
this.cmirror = this.editor.instance;
使用CodeMirror API(this.cmirror.setOption('...')
);
只要我在ViewChild参考上使用类型any
,一切正常。我已经下载了typings file了:
/// <reference path="../../typings/codemirror.d.ts" />
现在任何使用显式类型的尝试都失败了。
我试过了:@ViewChild('editor') editor: ElementRef
- 但.instance
不存在,所以我在IDE中遇到错误。
对于这样的内联模板引用模式,强烈键入ViewChild引用的正确方法是什么?