@@ -130,6 +130,18 @@ angular.module('ngCsv.services').
130
130
arrData = responseData ( ) ;
131
131
}
132
132
133
+ // Check if using keys as labels
134
+ if ( angular . isDefined ( options . label ) && options . label && typeof options . label === 'boolean' ) {
135
+ var labelArray , labelString ;
136
+
137
+ labelArray = [ ] ;
138
+ angular . forEach ( arrData [ 0 ] , function ( value , label ) {
139
+ this . push ( that . stringifyField ( label , options ) ) ;
140
+ } , labelArray ) ;
141
+ labelString = labelArray . join ( options . fieldSep ? options . fieldSep : "," ) ;
142
+ csvContent += labelString + EOL ;
143
+ }
144
+
133
145
angular . forEach ( arrData , function ( oldRow , index ) {
134
146
var row = angular . copy ( arrData [ index ] ) ;
135
147
var dataString , infoArray ;
@@ -208,7 +220,8 @@ angular.module('ngCsv.directives').
208
220
lazyLoad : '@lazyLoad' ,
209
221
addByteOrderMarker : "@addBom" ,
210
222
ngClick : '&' ,
211
- charset : '@charset'
223
+ charset : '@charset' ,
224
+ label : '&csvLabel'
212
225
} ,
213
226
controller : [
214
227
'$scope' ,
@@ -239,6 +252,7 @@ angular.module('ngCsv.directives').
239
252
} ;
240
253
if ( angular . isDefined ( $attrs . csvHeader ) ) options . header = $scope . $eval ( $scope . header ) ;
241
254
if ( angular . isDefined ( $attrs . csvColumnOrder ) ) options . columnOrder = $scope . $eval ( $scope . columnOrder ) ;
255
+ if ( angular . isDefined ( $attrs . csvLabel ) ) options . label = $scope . $eval ( $scope . label ) ;
242
256
243
257
options . fieldSep = $scope . fieldSep ? $scope . fieldSep : "," ;
244
258
@@ -279,12 +293,13 @@ angular.module('ngCsv.directives').
279
293
navigator . msSaveBlob ( blob , scope . getFilename ( ) ) ;
280
294
} else {
281
295
282
- var downloadLink = angular . element ( '<a></a>' ) ;
296
+ var downloadContainer = angular . element ( '<div data-tap-disabled="true"><a></a></div>' ) ;
297
+ var downloadLink = angular . element ( downloadContainer . children ( ) [ 0 ] ) ;
283
298
downloadLink . attr ( 'href' , window . URL . createObjectURL ( blob ) ) ;
284
299
downloadLink . attr ( 'download' , scope . getFilename ( ) ) ;
285
300
downloadLink . attr ( 'target' , '_blank' ) ;
286
301
287
- $document . find ( 'body' ) . append ( downloadLink ) ;
302
+ $document . find ( 'body' ) . append ( downloadContainer ) ;
288
303
$timeout ( function ( ) {
289
304
downloadLink [ 0 ] . click ( ) ;
290
305
downloadLink . remove ( ) ;
0 commit comments