我无法将我的ace编辑器设置为只读模式。我正在使用angular 9,并尝试了以下方法:
在HTML文件中,我有:
<ace-editor mode="java" theme="monokai" id="codeEditor"></ace-editor>在我的typescript文件中,我有:
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编辑器中编写代码。
发布于 2020-09-12 01:18:19
检查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>
https://stackoverflow.com/questions/63838198
复制相似问题