Those who have used AngularJS should be most interested in its commands. Currently, only AngularJS supports custom commands, and AngularJS is the only framework that provides reusable Web applications. Currently, angularJS is very popular and I am gradually using this technology in projects. In angularJS, commands can be said to be a very important part. Here I will share some self-compiled commands:
Note: I used oclazyload in my project to load some JS files.
1. KindEditor
The Code is as follows:
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: '200 ',
Height: '400p ',
ResizeType: 1,
UploadJson: '/Upload/upload_ajax.ashx ',
FormatUploadUrl: false,
AllowFileManager: true,
AfterChange: function (){
Ctrl.20.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:
The Code is as follows:
Angular. module ("AdminApp"). directive ('uieditor', ["uiLoad", "$ compile", function (uiLoad, $ compile ){
Return {
Restrict: 'ea ',
Require :'? Ngmodel ',
Link: function (scope, element, attrs, ctrl ){
UiLoad. load (['../Areas/AdminManage/Content/Vendor/jquery/ueditor. config. js ',
'../Areas/AdminManage/Content/Vendor/jquery/ueditor. all. js']). then (function (){
Var _ self = this,
_ InitContent,
Editor,
EditorReady = false
Var fexUE = {
InitEditor: function (){
Var _ self = this;
If (typeof UE! = 'Undefined '){
Editor = new UE. ui. Editor ({
InitialContent: _ initContent,
AutoHeightEnabled: false,
AutoFloatEnabled: false
});
Editor. render (element [0]);
Editor. ready (function (){
EditorReady = true;
_ Self. setContent (_ initContent );
Editor. addListener ('contentchange', function (){
Scope. $ apply (function (){
Ctrl. $ setViewValue (editor. getContent ());
});
});
});
}
},
SetContent: function (content ){
If (editor & editorReady ){
Editor. setContent (content );
}
}
};
If (! Ctrl ){
Return;
}
_ InitContent = ctrl. $ viewValue;
Ctrl. $ render = function (){
_ InitContent = ctrl. $ isEmpty (ctrl. $ viewValue )? '': Ctrl. $ viewValue;
FexUE. setContent (_ initContent );
};
FexUE. initEditor ();
});
}
};
}]);
3. jquery. Datatable:
The Code is as follows:
Angular. module ('adminapp'). directive ('uiable able', ['uiload', '$ compile', function (uiLoad, $ compile ){
Return function ($ scope, $ element, attrs ){
$ Scope. getChooseData = function (){
Var listID = "";
Var chooseData = $ element. find ("input [name = IsChoose]: checkbox: checked ");
If (chooseData. length> 0 ){
For (var I = 0; I <chooseData. length; I ++ ){
ListID + = chooseData [I]. value + ",";
}
}
Return listID. substring (0, listID. length-1 );
}
$ Scope. refreshTable = function (){
$ Scope. dataTable. fnClearTable (0); // clear data
$ Scope. dataTable. fnDraw (); // reload data
}
UiLoad. load (['../Areas/AdminManage/Content/Vendor/jquery/datatables/jquery. dataTables. min. js ',
'../Areas/AdminManage/Content/Vendor/jquery/datatables/dataTables. bootstrap. js ',
'../Areas/AdminManage/Content/Vendor/jquery/datatables/dataTables.bootstrap.css']). then (function (){
Var options = {};
If ($ scope. dtOptions ){
Angular. extend (options, $ scope. dtOptions );
}
Options ["processing"] = false;
Options ["info"] = false;
Options ["serverSide"] = true;
Options ["language"] = {
"Processing": 'loading ...',
"LengthMenu": "Number of _ MENU _ records displayed on each page ",
"ZeroRecords ":'
No relevant data found
',
"Info": "PAGE _ PAGES displayed currently ",
"InfoEmpty": "null ",
"InfoFiltered": "_ MAX _ records found ",
"Search": "search ",
"Paginate ":{
"First": "Homepage ",
"Previous": "previous Page ",
"Next": "next page ",
"Last": "last page"
}
}
Options ["fnRowCallback"] = function (nRow, aData, iDisplayIndex, iDisplayIndexFull ){
$ Compile (nRow) ($ scope );
}
$ Scope. dataTable = $ element. dataTable (options );
});
$ Element. find ("thead th"). each (function (){
$ (This). on ("click", "input: checkbox", function (){
Var that = this;
$ (This). closest ('table'). find ('tr> td: first-child input: checkbox'). each (function (){
This. checked = that. checked;
$ (This). closest ('tr'). toggleClass ('selected ');
});
});
})
}
}]);
The above three are my AngularJS commands, which I hope will be helpful to my friends,