diff --git a/src/ng-csv/directives/ng-csv.js b/src/ng-csv/directives/ng-csv.js index bfb80f9..f63801d 100644 --- a/src/ng-csv/directives/ng-csv.js +++ b/src/ng-csv/directives/ng-csv.js @@ -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(); }); } }; - }]); + }]); \ No newline at end of file diff --git a/src/ng-csv/services/csv-service.js b/src/ng-csv/services/csv-service.js index 3adade6..dae0c13 100644 --- a/src/ng-csv/services/csv-service.js +++ b/src/ng-csv/services/csv-service.js @@ -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); + } +});