目前angularJS非常火热,本人也在项目中逐渐使用该技术,在angularJS中,指令可以说是当中非常重要的一部分,这里分享一些自己编写的指令:
注:本人项目中用了oclazyload进行部分JS文件加载
1、KindEditor
复制代码 代码如下:
angular.module('AdminApp').directive('uiKindeditor', ['uiLoad', function (uiLoad) {
return {
restrict: 'EA',
require: '?ngModel',
link: function (scope, element, attrs, ctrl) {
uiLoad.load('../Areas/AdminManage/Content/Vendor/jquery/kindeditor/kindeditor-all.js').then(function () {
var _initContent, editor;
var fexUE = {
initEditor: function () {
editor = KindEditor.create(element[0], {
width: '100%',
height: '400px',
resizeType: 1,
uploadJson: '/Upload/Upload_Ajax.ashx',
formatUploadUrl: false,
allowFileManager: true,
afterChange: function () {
ctrl.$setViewValue(this.html());
}
});
},
setContent: function (content) {
if (editor) {
editor.html(content);
}
}
}
if (!ctrl) {
return;
}
_initContent = ctrl.$viewValue;
ctrl.$render = function () {
_initContent = ctrl.$isEmpty(ctrl.$viewValue) ? '' : ctrl.$viewValue;
fexUE.setContent(_initContent);
};
fexUE.initEditor();
});
}
}
}]);
2、UEditor:
复制代码 代码如下: