Preview Image before uploading Angularjs

前端 未结 4 638
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 04:10

Hi I was wondering if there was a way to preview images before I upload them using angularjs? I am using the this library. https://github.com/danialfarid/angular-file-uploa

4条回答
  •  独厮守ぢ
    2020-11-28 04:56

      // start Picture Preview    
        $scope.imageUpload = function (event) {
            var files = event.target.files;
    
            for (var i = 0; i < files.length; i++) {
                var file = files[i];
                var reader = new FileReader();
                reader.onload = $scope.imageIsLoaded;
                reader.readAsDataURL(file);
            }
        }
    
        $scope.imageIsLoaded = function (e) {
            $scope.$apply(function () {
                $scope.img = e.target.result;            
            });
        }
    
    
    
    
    

提交回复
热议问题