javascript - Getting around Typescript with ngImgCrop -


i'm new coding , have opportunity small stories on project whet teeth. right i'm working on getting profile picture selection , cropping webapp angularjs. i've selected ngimgcropper handle cropping. here's jsfiddle boilerplate code: http://jsfiddle.net/a2ew3yhf/50/

and here's javascript link:

var handlefileselect=function(evt) {   var file=evt.currenttarget.files[0];   var reader = new filereader();   reader.onload = function (evt) {     $scope.$apply(function($scope){         $scope.myimage = evt.currenttarget.result;     });   };     reader.readasdataurl(file); }; 

here's problem. project uses typescript, doesn't support evt.currenttarget.result, following error:

property 'result' not exist on type 'eventtarget' 

is there way around this?

simple solution

if sure property exist make below

 var handlefileselect=function(evt) {       var file=evt.currenttarget.files[0];       var reader = new filereader();       reader.onload = function (evt) {              $scope.$apply(function($scope){                   $scope.myimage = (<any>evt.currenttarget).result;               });       };       reader.readasdataurl(file);  }; 

also can create own interface describe target

  interface mytarget {         result:any;   //or type of image   }    //skip code  $scope.myimage = (evt.currenttarget mytarget).result; 

complicated solution

you can provide own declaration of ngimagecroper or provide description current event

   var handlefileselect=function(evt: imagecropevent){         //your    stuff    } 

resource

  1. write d.ts file

Comments