ng2-codemirror - 如何将自定义关键字添加到自动完成(提示)

时间:2017-12-20 05:38:10

标签: angular autocomplete keyword codemirror

我想添加从ng2-codemirror编辑器中的API调用获取的自定义自动完成列表(提示)。我从SO中找到了这个解决方案[CodeMirror AutoComplete Custom List]。但我在访问时遇到错误,

CodeMirror.hint.javascript // ERROR TypeError: Cannot read property 'javascript' of undefined

这是我的组件类。

import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';

import "codemirror/lib/codemirror";
import "codemirror/mode/javascript/javascript";
import "codemirror/addon/hint/show-hint";
import "codemirror/addon/hint/javascript-hint";

declare let CodeMirror: any;

@Component({
  selector: 'my-editor',
  templateUrl: './editor.component.html',
  styleUrls: ['./editor.component.scss']
})
export class SearchComponent implements AfterViewInit {

  @ViewChild('editor') editor;
  query: string = '';

  config = {
    mode: 'javascript',
    lineNumbers: false,
    theme: 'eclipse',
    extraKeys: {"Ctrl-Space": "autocomplete"},
  };

  constructor(private searchService: SearchService) {
  }

  ngAfterViewInit(): void {
    console.log(this.editor.instance);
    let orig = CodeMirror.hint.javascript; 
    console.log(orig);
  }
}

是否有人知道针对此问题的修复方法,或者有更好的方法将自定义关键字添加到自动完成下拉菜单。

由于

0 个答案:

没有答案