{"action":"created","issue":{"url":"https://api.github.com/repos/marmelab/ng-admin/issues/873","labels_url":"https://api.github.com/repos/marmelab/ng-admin/issues/873/labels{/name}","comments_url":"https://api.github.com/repos/marmelab/ng-admin/issues/873/comments","events_url":"https://api.github.com/repos/marmelab/ng-admin/issues/873/events","html_url":"https://github.com/marmelab/ng-admin/issues/873","id":124409312,"number":873,"title":"Issue with custom directive to upload excel","user":{"login":"frank0ch0a","id":2018618,"avatar_url":"https://avatars.githubusercontent.com/u/2018618?v=3","gravatar_id":"","url":"https://api.github.com/users/frank0ch0a","html_url":"https://github.com/frank0ch0a","followers_url":"https://api.github.com/users/frank0ch0a/followers","following_url":"https://api.github.com/users/frank0ch0a/following{/other_user}","gists_url":"https://api.github.com/users/frank0ch0a/gists{/gist_id}","starred_url":"https://api.github.com/users/frank0ch0a/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frank0ch0a/subscriptions","organizations_url":"https://api.github.com/users/frank0ch0a/orgs","repos_url":"https://api.github.com/users/frank0ch0a/repos","events_url":"https://api.github.com/users/frank0ch0a/events{/privacy}","received_events_url":"https://api.github.com/users/frank0ch0a/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-30T22:40:32Z","updated_at":"2016-01-01T16:45:25Z","closed_at":"2015-12-31T06:47:18Z","body":"Hello I created custom directive to upload excel file this is not working , o upload a excel sheet, when I upload the file, I get the following TypeError: Cannot set property 'columnDefs' of undefined, my code, it seem that the data is no passing from controller to directive.\r\n\r\nModule\r\n          var myApp = angular.module('myApp', ['ng-  admin','ngStorage','chart.js','ui.grid']);\r\n\r\nController\r\n\r\n    myApp.controller('MainCtrl', ['$scope', function ($scope) {\r\n\r\n    var vm = this;\r\n\r\n    vm.gridOptions = {};\r\n\r\n     vm.reset = reset;\r\n\r\n\r\n     function reset() {\r\n\r\n        vm.gridOptions.data = [];\r\n        vm.gridOptions.columnDefs = [];\r\n      }\r\n      }]);\r\n\r\nDirective\r\n\r\n     myApp.directive('fileread', ['$http', function ($http) {\r\n\r\n\r\n       return {\r\n       restrict: 'E',\r\n       scope: {\r\n       opts: '='\r\n        },\r\n\r\n    link: function ($scope, $elm, $attrs) {\r\n\r\n     $elm.on('change', function (changeEvent) {\r\n      var reader = new FileReader();\r\n\r\n        reader.onload = function (evt) {\r\n        $scope.$apply(function () {\r\n         var data = evt.target.result;\r\n\r\n       var workbook = XLSX.read(data, {type: 'binary'});\r\n\r\n       var headerNames = XLSX.utils.sheet_to_json(   workbook.Sheets[workbook.SheetNames[0]], { header: 1 })[0];\r\n\r\n       var datasheet = XLSX.utils.sheet_to_json( workbook.Sheets[workbook.SheetNames[0]]);\r\n\r\n       console.log(datasheet);\r\n\r\n\r\n       $scope.opts.columnDefs = [];\r\n\r\n       headerNames.forEach(function (h) {\r\n         $scope.opts.columnDefs.push({ field: h });\r\n       });\r\n\r\n       $scope.opts.data = datasheet;\r\n       var json_string = JSON.stringify($scope.opts.data);\r\n       console.log(json_string);\r\n\r\n       $elm.val(null);\r\n        });\r\n      };\r\n\r\n       reader.readAsBinaryString(changeEvent.target.files[0]);\r\n     });\r\n\r\n    }, template:\r\n       '<div ng-controller=\"MainCtrl as vm\">'+\r\n       '<button type=\"button\" class=\"btn btn-success\" ng-click=\"vm.reset()\">Reset Grid</button>'+\r\n       '<br />'+\r\n       '<br />'+\r\n       '<div id=\"grid1\" ui-grid=\"vm.gridOptions\" class=\"grid\">'+\r\n       '<div class=\"grid-msg-overlay\" \r\n        ng-show=\"!vm.gridOptions.data.length\">'+\r\n        '<div class=\"msg\">'+\r\n        '<div class=\"center\">'+\r\n          '<span class=\"muted\">Select Spreadsheet File</span>'+\r\n          '<br />'+\r\n          '<input type=\"file\" accept=\".xls,.xlsx,.ods\" fileread=\"\"     opts=\"vm.gridOptions\" multiple=\"false\" />'+\r\n           '</div>'+\r\n          '</div>'+\r\n       '</div>'+\r\n     '</div>'+\r\n     '</div>'\r\n\r\n\r\n\r\n      }\r\n\r\n     }]);\r\n\r\n\r\nTemplate from I am calling the directive\r\n\r\nDashboard Template\r\n\r\n       var customDashboardTemplate =\r\n       '<div class=\"row dashboard-starter\"></div>' +\r\n       '<question-stats></question-stats>'+\r\n       '<div ng-controller=\"MainCtrl\" >'+\r\n       '<fileread>'+\r\n       '<button type=\"button\" class=\"btn btn-success\" ng-click=\"reset()\">Reset Grid</button>'+\r\n       '<br />'+\r\n       '<br />'+\r\n       '<div id=\"grid1\" ui-grid=\"gridOptions\" class=\"grid\">'+\r\n       '<div class=\"grid-msg-overlay\" ng-show=\"!gridOptions.data.length\">'+\r\n       '<div class=\"msg\">'+\r\n       '<div class=\"center\">'+\r\n        '<span class=\"muted\">Select Spreadsheet File</span>'+\r\n        '<br />'+\r\n        '<input type=\"file\" accept=\".xls,.xlsx,.ods\" fileread=\"\"  opts=\"gridOptions\" multiple=\"false\" />'+\r\n         '</div>'+\r\n         '</div>'+\r\n         '</div>'+\r\n         '</div>'+\r\n         '</fileread>'+\r\n         '</div>'+\r\n        '<div class=\"row dashboard-content\">' +\r\n       '<div class=\"col-md-6\">' +\r\n        '<div class=\"panel panel-green\">' +\r\n         '<ma-dashboard-panel collection=\"dashboardController.collections.last_users\"  entries=\"dashboardController.entries.last_users\" datastore=\"dashboardController.datastore\"></ma-dashboard-panel>' +\r\n        '</div>' +\r\n      '</div>'+\r\n\r\n    '<div class=\"col-md-6\">' +\r\n        '<div class=\"panel panel-yellow\">' +\r\n          '<ma-dashboard-panel collection=\"dashboardController.collections.last_tips\"  entries=\"dashboardController.entries.last_tips\" datastore=\"dashboardController.datastore\"></ma-dashboard-panel>' +\r\n        '</div>' +\r\n        '</div>'+\r\n      '</div>'+\r\n      '</div>'\r\n       ;\r\n"},"comment":{"url":"https://api.github.com/repos/marmelab/ng-admin/issues/comments/168316421","html_url":"https://github.com/marmelab/ng-admin/issues/873#issuecomment-168316421","issue_url":"https://api.github.com/repos/marmelab/ng-admin/issues/873","id":168316421,"user":{"login":"frank0ch0a","id":2018618,"avatar_url":"https://avatars.githubusercontent.com/u/2018618?v=3","gravatar_id":"","url":"https://api.github.com/users/frank0ch0a","html_url":"https://github.com/frank0ch0a","followers_url":"https://api.github.com/users/frank0ch0a/followers","following_url":"https://api.github.com/users/frank0ch0a/following{/other_user}","gists_url":"https://api.github.com/users/frank0ch0a/gists{/gist_id}","starred_url":"https://api.github.com/users/frank0ch0a/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frank0ch0a/subscriptions","organizations_url":"https://api.github.com/users/frank0ch0a/orgs","repos_url":"https://api.github.com/users/frank0ch0a/repos","events_url":"https://api.github.com/users/frank0ch0a/events{/privacy}","received_events_url":"https://api.github.com/users/frank0ch0a/received_events","type":"User","site_admin":false},"created_at":"2016-01-01T16:45:25Z","updated_at":"2016-01-01T16:45:25Z","body":"I'm sorry , but my intention was not to cross -post , but I'm worried because I do not get the solution and have not your experienced , thank you and excuse me for post again."}}