Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript google chrome中显示Pdf文件的Angularjs代码不起作用,但适用于firefox_Javascript_Angularjs_Google Chrome_Firefox_Pdf - Fatal编程技术网

Javascript google chrome中显示Pdf文件的Angularjs代码不起作用,但适用于firefox

Javascript google chrome中显示Pdf文件的Angularjs代码不起作用,但适用于firefox,javascript,angularjs,google-chrome,firefox,pdf,Javascript,Angularjs,Google Chrome,Firefox,Pdf,下面的代码在google chrome中显示Pdf文件不起作用,但在firefox中起作用 HTML视图 <div> <object ng-bind="pdfcontent" data="{{pdfcontent}}" type="application/pdf" width="100%" height="800px"> </object> </div> 我犯了两个错误 firebug lite.js:18877未捕获的Inval

下面的代码在google chrome中显示Pdf文件不起作用,但在firefox中起作用

HTML视图

<div>
    <object ng-bind="pdfcontent" data="{{pdfcontent}}" type="application/pdf" width="100%" height="800px">
    </object>
</div>
我犯了两个错误

firebug lite.js:18877未捕获的InvalidStateError:无法读取 “XMLHttpRequest”中的“responseText”属性:该值仅为 如果对象的“responseType”为“”或“text”(为),则可以访问 “arraybuffer”)(匿名函数)@firebug lite.js:18877

js:2812获取404(不是 发现)

我的代码中有什么错误,如何修复,非常感谢您的帮助。
谢谢。

您的问题是,对象呈现后,
数据
属性被绑定,因此当您的请求响应时,
pdfcontent
未被绑定

要解决这个问题,你可以做两件事

  • 为此目的使用指令,如
  • 您可以使用下面代码段中的
    if
    语句
  • $scope.download=false
    $http.get('/myurl/',{responseType:'arraybuffer'})。成功(函数(数据){
    $scope.download=true
    var file=newblob([data],{type:'application/pdf'});
    var fileURL=URL.createObjectURL(文件);
    $scope.pdfcontent=$sce.trustAsResourceUrl(fileURL);
    });
    
    您的问题是,一旦对象被呈现,
    数据
    属性就被绑定,因此当您的请求响应时,
    pdfcontent
    就没有被绑定

    要解决这个问题,你可以做两件事

  • 为此目的使用指令,如
  • 您可以使用下面代码段中的
    if
    语句
  • $scope.download=false
    $http.get('/myurl/',{responseType:'arraybuffer'})。成功(函数(数据){
    $scope.download=true
    var file=newblob([data],{type:'application/pdf'});
    var fileURL=URL.createObjectURL(文件);
    $scope.pdfcontent=$sce.trustAsResourceUrl(fileURL);
    });
    
    
    
    url有效吗(您可以在浏览器中打开)?是的url有效且正确,它在firefox中工作。url有效吗(您可以在浏览器中打开)?是的url有效且正确,它在firefox中工作。
    $http.get('/myurl/', {responseType: 'arraybuffer'})
        .success(function (data) {
        var file = new Blob([data], {type: 'application/pdf'});
        var fileURL = URL.createObjectURL(file);
        $scope.pdfcontent = $sce.trustAsResourceUrl(fileURL);
    });