The anchor tag in your plunkr is missing ng-href="{{ csv.link() }}
, which forces the browser to load csv into a file.
If you must use the button instead of the anchor tag, you can simulate the href
function, which calls csv.generate
, and then sets location.href
to the value returned by csv.link()
:
$scope.exportFile = function($event, fileName) { $scope.csv.generate($event, "report.csv"); location.href=$scope.csv.link(); };
But since you want the button and table to come from different template files, they are probably associated with different child areas . A quick workaround for this is to tell the export directive to create a csv
helper for the object that exists in the $parent
scope:
<table ng-table="tableParams" export-csv="helper.csv">
Then change your controller to:
$scope.helper = { csv: null //will be replaced by the export directive }; $scope.exportFile = function($event, fileName) { $scope.helper.csv.generate($event, "report.csv"); location.href=$scope.helper.csv.link(); };
Here is a working demo: http://plnkr.co/edit/a05yJZC1pkwggFUxWuEM?p=preview
source share