Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new implement: Implemented an event call after and before Csv file export. issue ID: #166 #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
new implement: Implemented an event call after and before Csv file ex…
…port, issue ID: #166
Hemakumar committed Jun 16, 2016
commit c5c57f49432b5d6f4fd94c7db176011ab69fdbc7
6 changes: 4 additions & 2 deletions src/ng-csv/directives/ng-csv.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
* Author: asafdav - https://github.com/asafdav
*/
angular.module('ngCsv.directives').
directive('ngCsv', ['$parse', '$q', 'CSV', '$document', '$timeout', function ($parse, $q, CSV, $document, $timeout) {
directive('ngCsv', ['$parse', '$q', 'CSV', '$document', '$timeout', 'CSVBroadcast', function ($parse, $q, CSV, $document, $timeout, CSVBroadcast) {
return {
restrict: 'AC',
scope: {
@@ -108,11 +108,13 @@ angular.module('ngCsv.directives').
}

element.bind('click', function (e) {
CSVBroadcast.broadcastEvent("CSV.beforeDownload");
scope.buildCSV().then(function (csv) {
doClick();
CSVBroadcast.broadcastEvent("CSV.downloaded");
});
scope.$apply();
});
}
};
}]);
}]);
22 changes: 22 additions & 0 deletions src/ng-csv/services/csv-service.js
Original file line number Diff line number Diff line change
@@ -167,3 +167,25 @@ angular.module('ngCsv.services').


}]);

angular.module('ngCsv.services').
service('CSVBroadcast', function ($rootScope) {
/**
* Helper function to calling an event after export
* Function calls $rootScope.$broadcast(@eventName)
* @param eventName
*/
this.broadcastEvent = function(eventName){
$rootScope.$broadcast(eventName);
}

/**
* Helper function to calling an event after export
* Function invoked when event fired on $rootScope.$broadcast(@intput)
* callback function executed on event
* @param eventName
*/
this.listenEvent = function(eventName, callback) {
$rootScope.$on(eventName,callback);
}
});