I saw that this question was asked several times, but I could not understand how the answers relate to my problem. I keep getting this error while trying to upload a file.
Error: Non-assignable model expression: undefined (directive: fileReader)
How could I solve this?
I have included all the files that interact with each other, although I am pretty sure that the error occurs in fileDirective.js
fileDirective.js. contains this directive:
spreadsheetApp.directive('fileReader', function() { return { scope: { file: '=' }, restrict: 'E', template: "<input type='file' onchange='angular.element(this).scope().upload(this)'>", link: function (scope, element, attrs) { scope.upload = function (element) { scope.$apply(function (scope) { scope.file = element.files[0]; }); }; scope.$watch('file', function () { if (scope.file) { var reader = new FileReader(); reader.onload = (function (file) { return function (env) { scope.$apply(function () { scope.file.contents = env.target.result; }); } }(scope.file)); reader.readAsText(scope.file); } }, true); } }; });
(It was actually borrowed from here .)
index.html:
<html ng-app="spreadsheetApp"> ... <ng-view></ng-view> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> <script src="js/app.js"></script> <script src="js/directives/fileDirective.js"></script> <script src="js/controllers/spreadsheetController.js"></script> ... </html>
app.js: "use strict";
var spreadsheetApp = angular.module('spreadsheetApp',[]); spreadsheetApp.config(function($routeProvider) { $routeProvider. when('/', { controller: 'spreadsheetController', templateUrl: 'views/innerHTML.html' }); });
And the contents of innerHTML.html is simple: <file-reader> </file-reader>
source share