Sye*_*eed 5 javascript angularjs angularjs-directive angularjs-scope angularjs-ng-repeat
这是我的控制器代码
$scope.aceOptions = {
workerPath: 'http://localhost:50871/Scripts/app/vendor/',
useWrapMode: true,
showGutter: true,
theme: 'chrome',
firstLineNumber: 1,
onLoad: function (_editor) {
$scope.script = {};
$scope.script.scriptCode = "function fieldName_columnName_" + "functionName(){\n\n\n}";
var _session = _editor.getSession();
_session.setMode('ace/mode/javascript');
var _renderer = _editor.renderer;
_session.on('changeAnnotation', function () {
$scope.annotations = [];
$scope.annotations = _editor.getSession().getAnnotations();
}),
_editor.$blockScrolling = Infinity;
_session.on("change", function (e) {
var currentValue = _editor.getSession().getValue();
$scope.script.scriptCode = currentValue;
});
},
require: ['ace/ext/language_tools'],
advanced: {
enableSnippets: true,
enableBasicAutocompletion: true,
enableLiveAutocompletion: true
}
}
Run Code Online (Sandbox Code Playgroud)
我为ui-ace写了指令这是我的html代码
<javascript-editor code="script.scriptCode" ace-option="aceOptions"></javascript-editor>
Run Code Online (Sandbox Code Playgroud)
和指令代码是
SCSApp
.directive('javascriptEditor', [
function () {
return {
restrict: 'E',
scope: {
data: '=code',
aceOption: '='
},
templateUrl: '/Scripts/app/shared/directives/javascripEditor/partials/javascriptEditor.html',
link: function (scope, element, attrs) {
}
}
}]);
Run Code Online (Sandbox Code Playgroud)
这是我的javascriptEditor.html
<div class="e1" ui-ace="aceOption" ng-model="data"></div>
Run Code Online (Sandbox Code Playgroud)
我只想限制用户不要在ui-ace编辑器中编写更多的javascript函数
您可以创建自己的 javascript 简单函数解析器或使用像parser3这样的库
然后编写逻辑规则,根据ACE编辑器的内容向UI显示成功/失败。
它是像编译器一样的字符串/句子解析,以创建低级代码。