angularJS display base64 image

前端 未结 4 2102
时光说笑
时光说笑 2020-11-29 01:42

In my app i try to display base64 image...

for example i have:

/9j/4QNaRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAA         


        
4条回答
  •  半阙折子戏
    2020-11-29 02:14

    If the image is from remote server, you can fetch the base64 content in your controller like this:

    $http.get($scope.user.photo).then(function(response) {
        $scope.user.data = response.data;
    });
    

    then display it on view

    
    

    While if the image is on local disk/phone, first you can get the image data from FileReader

    var fileInput = document.getElementById("myfileinput");
    
    // files is a FileList object (similar to NodeList)
    var files = fileInput.files;
    $scope.imageSrc = files[0].getAsDataURL();
    

    then bind the $scope.imageSrc to view as

提交回复
热议问题