html页面:<pre id="editor" style=" 100%;height: 800px;"></pre>(注:必须设置高度)
function getScriptHightLight(){
ace.config.set("basePath", "vendors/ace-build/src-min");
ace.require("ace/ext/beautify");
var editor = ace.edit("editor");
if($scope.store&&$scope.store.scriptContent){
editor.setValue($scope.store.scriptContent); //设置内容
if($scope.oper==="detail"){
editor.setReadOnly(true); //只读
}else{
editor.setReadOnly(false); //只读
}
}else{
editor.setValue('');//没有值设置为空
}
editor.setOption("wrap", "free") //自动换行
editor.setShowPrintMargin(false); //设置打印线
editor.session.setMode("ace/mode/sh");
editor.setTheme("ace/theme/vibrant_ink"); //引入的模板
editor.setHighlightActiveLine(true); //设置高亮
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
editor.on('change', function () {//更新脚本事件
$timeout(function () {
$scope.$apply(function () {
var value = editor.getValue();
$scope.store.scriptContent=value;
});
});
});
}