Javascript 角镜和编码镜

Javascript 角镜和编码镜,javascript,angularjs,dom,codemirror,Javascript,Angularjs,Dom,Codemirror,我一直在尝试向javascript工具添加一些功能,我需要突出显示codemirr中的一行。我使用的是AngularJs。 首先,我试着遵循一个教程 function highlightLine(lineNumber) { //Line number is zero based index var actualLineNumber = lineNumber - 1; //Select editor loaded in the DOM var myEditor

我一直在尝试向
javascript
工具添加一些功能,我需要突出显示
codemirr
中的一行。我使用的是
AngularJs
。 首先,我试着遵循一个教程

function highlightLine(lineNumber) {

    //Line number is zero based index
    var actualLineNumber = lineNumber - 1;

    //Select editor loaded in the DOM
    var myEditor = $("#body_EditorSource .CodeMirror");

    //Write the item to the console window, for debugging
    console.log(myEditor);

    //Select the first item (zero index) just incase more than one found & get the CodeMirror JS object
    var codeMirrorEditor = myEditor[0].CodeMirror;

    //Write the item to the console window, for debugging
    console.log(myEditor[0].CodeMirror);

    //Set line CSS class to the line number & affecting the background of the line with the css class of line-error
    codeMirrorEditor.setLineClass(actualLineNumber, 'background', 'line-error');
}
但是它不工作,不检测
myEditor var
。。。我试过:

var myEditor = document.getElementById('codeMirrorDiv');
var myEditor = angular.element(document.querySelector((".codeMirrorDiv")));

什么也没有。问题似乎出在哪里?

在我注意到愚蠢的错误a之后,函数被调用了

是的://行号是基于零的索引var actualLineNumber=lineNumber-1//选择DOM var myEditor=angular.element(document.querySelector(“#codeMirrorDiv”))中加载的编辑器;var codeMirrorEditor=myEditor[0]。childNodes[0]。CodeMirror;addlineClass(actualLineNumber,'background','LineError');仍然不起作用在控制器中,您究竟在哪里使用此代码?指令?在什么时间,我在控制器的函数中使用,当用户选择一个结果扫描时,它会显示var线高亮显示蓝色。show_result(){…setvalue()//填充代码mirror setcursor()//设置光标sethighlight(3)//只是为了测试,hihglihg line blue}我们需要更多的上下文,你能做一个小提琴来显示问题吗?因为我猜你选错了。您不应该在控制器中使用jquery,而是应该生成一个指令;调试时,codemirroreditor在proto:Object中具有该功能,但为什么我不能访问它呢?