如何解决将Ace编辑器设置为只读
我无法将ace-editor设置为只读模式。我正在使用angular 9,并尝试了以下方法:
在HTML文件中,我有:
<ace-editor mode="java" theme="monokai" id="codeEditor"></ace-editor>
在我的打字稿文件中,我有:
import * as ace from 'ace-builds/src-noconflict/ace';
...
ngOnInit() {
var editor = ace.edit('codeEditor');
editor.getSession().setUseWorker(false);
editor.setShowPrintMargin(false);
editor.setReadOnly(true);
}
但是,加载模板后,我仍然可以在ace编辑器中编写代码。
解决方法
检查setReadOnly代码之前是否有错误,或者您的某些代码将readOnly更改回false,因为示例中的代码在下面的示例中可用
<script src=https://ajaxorg.github.io/ace-builds/src-noconflict/ace.js></script>
<div id=codeEditor style=height:80vh></div>
<script>
var editor = ace.edit('codeEditor');
editor.session.setUseWorker(false);
editor.setShowPrintMargin(false);
editor.setReadOnly(true);
</script>