2017-04-09 296 views
0

我想上傳圖像,並讓它顯示在屏幕上,但它不工作。誰能幫忙?我試圖立足我對這個示例解決方案:http://jsfiddle.net/kkhxsgLu/2/試圖上傳圖像,並讓它顯示在屏幕上

查看

<div class="col-sm-6"> 
    Upload image: 
    <br><br> 
    <input id="file" type="file" accept="image/*" ng-model="file" ng-onchange="vm.imageUpload(this)"/> 
    <br> 
    <img ng-src="{{ file }}" /> 
</div> 

控制器

var vm = this; 
vm.file = {}; 

vm.imageUpload = function() { 
    var reader = new FileReader(); 
    reader.onload = vm.imageIsLoaded; 
    reader.readAsDataURL(element.files[0]); 
}; 

vm.imageIsLoaded = function(e) { 
    vm.$apply(function() { 
    vm.file = e.target.result; 
    }) 
} 
+0

檢查:http://stackoverflow.com/questions/17063000/ng-model-for-input-type -文件 – Ved

回答