1

I'am trying to debug this code on IE. This code use AngularJS with a file input. It works fine on Chrome.

$scope.file_changed = function(element) {
      var files = element.files; // FileList object
      var can = document.getElementById('canvas');
      var ctx = can.getContext('2d');
      var photofile = element.files[0]
      var reader = new FileReader();
          reader.onload = (function(theFile) {
                return function(e) {

                  var img = new Image();
                  img.onload = function(){
                      can.width = img.width;
                         can.height = img.height;
                      ctx.drawImage(img,0,0);
                  }
                  img.src = event.target.result;

                  $scope.imageSource= e.target.result; 
                  $scope.$apply();  
                };
              })(photofile);
          reader.readAsDataURL(photofile); 
  }// End Method file_changed

and the html :

<input ng-model="photo"
           onchange="angular.element(this).scope().file_changed(this)"
           type="file" accept="image/*" /> 

The IE debugger say : SCRIPT5007: Impossible d’obtenir la propriété « result » d’une référence null ou non définie for this ligne : img.src = event.target.result;

I have the same buf on Firefox. Does anyone have an idea ?

mcbjam
  • 7,344
  • 10
  • 32
  • 40
  • @user1737909 that's an offensive way to make your point. OP, while that comment was rude, I completely agree. Your code is _very_ far from the way Angular code is 'meant to be written'. The fact you attach strings to the dom and don't use Angular's facilities will make development very un-pleasant. If you're looking for a good Angular tutorial, the official tutorial is fairly good. Also, I recommend you read http://stackoverflow.com/questions/14994391/how-do-i-think-in-angularjs-if-i-have-a-jquery-background – Benjamin Gruenbaum May 20 '13 at 18:44
  • people should **NOT** jump on technologies because they're hype and look cool even when they don't understand at all how it works underneath. Remember jQuery ? Now, that's true, that was *totally* uncalled for. sorry. – Ven May 20 '13 at 18:56
  • 1
    Hi. It's the first time i use angular js. i'm going step by step. I was able to bing some data and some function. I sill was not able to bind a canvas. For the file input, it was a solution i found on stack overflow. What else is wrong on my code ? – mcbjam May 20 '13 at 19:28
  • Ha yes, i wrote with jquery? I supress this code in a new version of my code. – mcbjam May 20 '13 at 19:33

0 Answers0