@@ -12,10 +12,11 @@ csvImport.directive('ngCsvImport', function() {
1212 header : '=' ,
1313 headerVisible : '=' ,
1414 separator : '=' ,
15+ separatorVisible : '=' ,
1516 result : '='
1617 } ,
17- template : '<div><div ng-show="header && headerVisible"><div class="label">Header</div><input type="checkbox" ng-model="header"></div>' +
18- '<div ng-show="separator " ><div class="label">Seperator</div><input type="text" ng-change="changeSeparator" ng-model="separator"></div>' +
18+ template : '<div><div ng-show="headerVisible"><div class="label">Header</div><input type="checkbox" ng-model="header"></div>' +
19+ '<div ng-show="separatorVisible " ><div class="label">Seperator</div><input type="text" ng-change="changeSeparator" ng-model="separator"></div>' +
1920 '<div><input class="btn cta gray" type="file"/></div></div>' ,
2021 link : function ( scope , element ) {
2122 element . on ( 'keyup' , function ( e ) {
@@ -32,6 +33,7 @@ csvImport.directive('ngCsvImport', function() {
3233
3334 element . on ( 'change' , function ( onChangeEvent ) {
3435 var reader = new FileReader ( ) ;
36+ scope . filename = onChangeEvent . target . files [ 0 ] . name ;
3537 reader . onload = function ( onLoadEvent ) {
3638 scope . $apply ( function ( ) {
3739 var content = {
@@ -42,8 +44,10 @@ csvImport.directive('ngCsvImport', function() {
4244
4345 scope . content = content . csv ;
4446 scope . result = csvToJSON ( content ) ;
47+ scope . result . filename = scope . filename ;
4548 } ) ;
4649 } ;
50+
4751 if ( ( onChangeEvent . target . type === "file" ) && ( onChangeEvent . target . files != null || onChangeEvent . srcElement . files != null ) ) {
4852 reader . readAsText ( ( onChangeEvent . srcElement || onChangeEvent . target ) . files [ 0 ] ) ;
4953 } else {
0 commit comments