html頁面:<pre id="editor" style="width: 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;
});
});
});
}