How to read a file in AngularJS?

后端 未结 3 624
时光取名叫无心
时光取名叫无心 2020-12-04 15:49

Is it possible to read files in AngularJS? I want to place the file into an HTML5 canvas to crop.

I was thinking of using a directive? This is the javascript code I

3条回答
  •  长情又很酷
    2020-12-04 16:44

    Yes, directives is a right way, but it looks little bit different:

    .directive("ngFileSelect",function(){    
      return {
        link: function($scope,el){          
          el.bind("change", function(e){          
            $scope.file = (e.srcElement || e.target).files[0];
            $scope.getFile();
          });          
        }        
      }
    })
    

    Working example: http://plnkr.co/edit/y5n16v?p=preview

    Thanks to lalalalalmbda for this link.

提交回复
热议问题