如何在ng-click上打开PDF文件而不是在Angularjs中下载?

时间:2016-09-06 06:23:50

标签: html angularjs

当用户点击此链接"Click to get your file"时,我可以下载该文件。但现在我需要打开PDF文件(如模态窗口)并限制用户下载文件。

我的控制器

var resumeJson = {
        "json":{
            "request":{
                "candidateid":$rootScope.globals.currentUser.userId,
                "type":2
             }
          }
       };


$scope.getResume = function() {

      console.log(JSON.stringify(resumeJson));
      $scope.resume = UserService.getFile(resumeJson);
      console.log($scope.resume);    
 }

我的Html

<div class="grid_3" ng-show="resumeflag==true || uploaded==true" ng-hide="resumeflag==false || uploaded==false">
   <a  ng-click="getResume()" href="{{resume}}">
       <img ng-src="images/resume.png" style="height:4em; width:4em;" ng-click="getResume()" href="{{resume}}">Click to get Your Resume</a>
</div>

1 个答案:

答案 0 :(得分:0)

iframe怎么样?

<强>控制器:

    var j$ = jQuery.noConflict();


    j$(document).ready(function() {
        j$('input[id$=btnCloseModalDialog]').click(function(event) {
            event.preventDefault();
            closeModalDialog();
        });
    });

   function closeModalDialog() {
        var cross_result = new Object();
        cross_result.action = 'close_modal_dialog_refresh';

        j$.postMessage(
          'hello world',
          'https://cs44.salesforce.com',
          parent
        );
    }

<强> HTML:

$scope.getResume = function() {
    UserService.getFile(resumeJson)
        .then(function(response) {
            var file = new Blob([response], {type: 'application/pdf', charset:'utf-8'});
            var fileURL = URL.createObjectURL(file);
            $scope.resume = $sce.trustAsResourceUrl(fileURL);
        });
}