2016-02-23 44 views
0

如何在AngularJS中的$on("fileSelected")之後顯示圖像?

我使用下列選擇一個文件:

$scope.$on("fileSelected", function (event, args) { 
     debugger; 
     $scope.$apply(function() { 
      $scope.file = args.file; 
     }); 

我需要顯示與IMG src屬性的圖像。

回答

2

嘗試是這樣的:

var reader = new FileReader(); 

    reader.onload = function (e) { 
     $('#image').attr('src', e.target.result); 
    } 

    reader.readAsDataURL(input.files[0]); 
+0

非常感謝:)玉米粥VAR –

+0

讀卡器=新的FileReader(); reader.onload = function(e){('#image')。attr('src',e.target.result); } reader.readAsDataURL(index.file); –