角度和代码镜像

时间:2014-08-01 08:44:57

标签: javascript angularjs dom codemirror

我一直在尝试向javascript工具添加一些功能,我需要在codemirror中突出显示一行。我正在使用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")));
什么也没有。这似乎是什么问题?

1 个答案:

答案 0 :(得分:1)

该函数名为addLineClass