javascript - BLOB object is not visible -


actually, trying image using $http , storing data in blob object can use after on

html

<body ng-app="myapp">  <div  ng-controller="homectrl"> <button ng-click="download()">download</button>     <img id="photo"/> </div> 

controller:

angular.module('myapp', []);  angular.module('myapp').controller('homectrl', ['$scope', '$http', function($scope, $http) {    $scope.download=function()   {      $http.get('https://placeholdit.imgix.net/~text?txtsize=15&txt=image1&w=120&h=120').success(function(data){     var arraybufferview = new uint8array( data );     var blob = new blob( [ arraybufferview ], { type: "image/png" } );     var urlcreator = window.url || window.webkiturl;     var imageurl = urlcreator.createobjecturl( blob );     var img = document.queryselector( "#photo" );     img.src = imageurl;          }).error(function(err, status){})   }  }]); 

plunker same problem:http://plnkr.co/edit/4kfksigcudilwoas2vsz?p=preview

you need set responsetype "arraybuffer"

$http.get('https://placeholdit.imgix.net/~text?txtsize=15&txt=image1&w=120&h=120', {responsetype: "arraybuffer"}) 

http://plnkr.co/edit/ikqkwky6ymwodzpbyx0f?p=preview


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -