Skip to content

Commit

Permalink
Fixes #66
Browse files Browse the repository at this point in the history
  • Loading branch information
asafdav committed Nov 25, 2014
1 parent 05903c5 commit 6053a5e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
17 changes: 10 additions & 7 deletions build/ng-csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,18 @@ angular.module('ngCsv.services').
csvContent += index < arrData.length ? dataString + EOL : dataString;
});

if(window.navigator.msSaveOrOpenBlob) {
csv = csvContent;
}else{
// IE uses the BLOB way so no need for DATA_URI_PREFIX
if(!window.navigator.msSaveOrOpenBlob) {
csv = DATA_URI_PREFIX;
if (options.addByteOrderMarker){
csv += BOM;
}
csv += csvContent;
}

// Add BOM if needed
if (options.addByteOrderMarker){
csv += BOM;
}

// Append the content and resolve.
csv += csvContent;
def.resolve(csv);
});

Expand Down
2 changes: 1 addition & 1 deletion build/ng-csv.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<html>
<head>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-sanitize.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-sanitize.min.js"></script>
<script src="../build/ng-csv.js"></script>
</head>
<body>
Expand All @@ -28,6 +28,7 @@ <h1>ngCsv <small>example</small></h1>
<button class="btn btn-default"
ng-csv="getArray" filename="{{ filename }}.csv" field-separator="{{separator}}"
>Export to CSV</button>

<button class="btn btn-default"
ng-csv="getArray" csv-header="getHeader()" filename="{{ filename }}" field-separator="{{separator}}"
>Export to CSV with header</button>
Expand All @@ -36,6 +37,10 @@ <h1>ngCsv <small>example</small></h1>
ng-csv="getArray" csv-header="getHeader()" filename="{{ filename }}" field-separator="{{separator}}"
ng-click="clickFn()">Export with ng-click</button>

<button class="btn btn-default"
ng-csv="getArray" filename="{{ filename }}.csv" field-separator="{{separator}}" add-bom="true"
>With BOM</button>

<button class="btn btn-default" ng-click="addRandomRow()">Add row</button>
</div>
</div>
Expand All @@ -50,7 +55,7 @@ <h1>ngCsv <small>example</small></h1>
$scope.addRandomRow = function() {
$scope.getArray.push({a: Math.floor((Math.random()*10)+1), b: Math.floor((Math.random()*10)+1)});
};

$scope.getHeader = function () {return ["A", "B"]};

$scope.clickFn = function() {
Expand Down
17 changes: 10 additions & 7 deletions src/ng-csv/services/csv-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,18 @@ angular.module('ngCsv.services').
csvContent += index < arrData.length ? dataString + EOL : dataString;
});

if(window.navigator.msSaveOrOpenBlob) {
csv = csvContent;
}else{
// IE uses the BLOB way so no need for DATA_URI_PREFIX
if(!window.navigator.msSaveOrOpenBlob) {
csv = DATA_URI_PREFIX;
if (options.addByteOrderMarker){
csv += BOM;
}
csv += csvContent;
}

// Add BOM if needed
if (options.addByteOrderMarker){
csv += BOM;
}

// Append the content and resolve.
csv += csvContent;
def.resolve(csv);
});

Expand Down

0 comments on commit 6053a5e

Please sign in to comment.