在ng2-ace-editor

时间:2019-07-11 06:08:10

标签: angular angular6 ace-editor

我在项目中使用ng2-ace-editor。我需要在出现错误的行号之前显示错误或警告指示。

我正在尝试此处描述的方式:https://github.com/fxmontigny/ng2-ace-editor/commit/11a9c4025465190e2c8e35081e09e51fb32e7848#diff-aa2cbbf8c50873cb0bf8e42f52cf1319

var Range = ace.require('ace/range').Range;

this.highlight.getEditor().session.addMarker(
  new Range(0, 0, 2, 1), "myMarker", "fullLine"
);

这在编辑器中没有执行任何操作。这就是在页面中调用编辑器的方式。

this.editor.getEditor().setOptions({
  enableBasicAutocompletion: editorOption.snippet,
  highlightActiveLine: editorOption.highlight,
  showLineNumbers: editorOption.line,
  enableSnippets: editorOption.snippet,
  enableLiveAutocompletion: editorOption.snippet,
  behavioursEnabled: editorOption.behaviours,
  wrapBehavioursEnabled: editorOption.wrapb,
  autoScrollEditorIntoView: editorOption.auto,
  wrap: editorOption.wrap,
  keyboardHandler: null,
  readOnly: editorOption.readonly
});

预先感谢您的帮助。

3 个答案:

答案 0 :(得分:1)

要显示错误或警告符号,可以使用setAnnotations:

this.editor._editor.getSession().setAnnotations([{
    row: 1,
    column: 0,
    text: "Error Message", // Or the Json reply from the parser 
    type: "error" // also "warning" and "information"
}]);

要获得会话,您可以使用

var _session = _editor.getSession();

答案 1 :(得分:1)

可以使用-

调用角度6中的ace编辑器的设置注释。
 this.editor._editor.session.setAnnotations([{ 
             row: 1, 
             column: 0, 
             text: "Error Message", // Or the Json reply from the par
             type: "error" // also "warning" and "information" 
 }]);

答案 2 :(得分:0)

我可以通过添加装订线信息来解决此问题。

this.editor._editor.session.addGutterDecoration( elementPosition, "fa fa-fire text-info gutterMessages"); 

感谢您的宝贵时间! :)

相关问题