html5 - Angular.js scope passing file reader errors -
i trying save text file string inside rootscope. have far directive, loads properly, , function checks root
function calldata($rootscope) { console.log("function working"); console.log($rootscope.data); } angular.module('spreadsheetapp').directive('filereader', function($rootscope) { return { restrict: 'e', scope: true, templateurl:'views/filereadertemplate.html', controller: 'filereadercontroller', link: function (scope, element, attributes, controller) { $element.bind("change", function(event) { var files = event.target.files; var reader = new filereader(); reader.onload = function() { $rootscope.data = this.result; console.log($rootscope.data); calldata($rootscope.data); console.log("55"); }; reader.readastext(files[0]); }); } } });
which returns following ouput textfile says:
# text file hello, world!
output:
hello, world! function working filedirective.js:44 uncaught typeerror: cannot read property 'data' of undefined filedirective.js:45 calldata filedirective.js:45 reader.onload
since you're trying access scope outside function, requires actions.
the answer question has been answered here: angularjs access scope outside js function
you need use code:
var scope = angular.element($("#yourelement")).scope();
Comments
Post a Comment