How to Display blob (.pdf) in an AngularJS app

后端 未结 8 1383
逝去的感伤
逝去的感伤 2020-11-22 11:01

I have been trying to display pdf file which I am getting as a blob from a $http.post response. The pdf must be displayed within the app using

8条回答
  •  悲&欢浪女
    2020-11-22 11:43

    michael's suggestions works like a charm for me :) If you replace $http.post with $http.get, remember that the .get method accepts 2 parameters instead of 3... this is where is wasted my time... ;)

    controller:

    $http.get('/getdoc/' + $stateParams.id,     
    {responseType:'arraybuffer'})
      .success(function (response) {
         var file = new Blob([(response)], {type: 'application/pdf'});
         var fileURL = URL.createObjectURL(file);
         $scope.content = $sce.trustAsResourceUrl(fileURL);
    });
    

    view:

    
    

提交回复
热议问题