简体   繁体   English

如何在AngularJS中连接jsReport?

[英]How to connect jsReport in AngularJS?

I have a problem now about JSReport.. It assumed that I already have an API...What I want now is how to link it with my Client Side which uses AngularJS. 我现在有一个关于JSReport的问题..它假设我已经有了一个API ...我现在想要的是如何将它与我使用AngularJS的客户端链接。

If I use Postman it will return a pdf file which is what I want. 如果我使用Postman,它将返回一个我想要的pdf文件。 But my problem is how to show it is my page when i post it using angularjs.. 但我的问题是当我使用angularjs发布它时如何显示它是我的页面..

I have a code like this : 我有这样的代码:

Controller 调节器

$scope.Print = function () {
        authService.print().then(function(result){
            var _result = result;
        });
    };

Service 服务

var _print = function () {
        var data = { "template": { "shortid": "byQtwHLPQ" } };
        return $http.post("http://192.168.8.87/api/report", data).then(function (result) {
            return result;
        });
    };

authServiceFactory.print = _print;

Now I have that Code and its not working... I assumed it has no return so I remove the return and just post but still it didn't work and even downloading the pdf didn't work on it. 现在我有了这个代码并且它不起作用......我认为它没有返回所以我删除了返回并且只是发布但是它仍然没有用,甚至下载pdf也没有用。

Anyone can help Please... 有人可以帮忙吗...

Use like this one.. 像这样使用..

Controller 调节器

var parameter = { "template": { "shortid": "ZkMoslfdX" }};
        PrintService.Print(parameter).then(function (result) {
            var file = new Blob([result.data], { type: 'application/pdf' });
            var fileURL = URL.createObjectURL(file);
            $scope.content = $sce.trustAsResourceUrl(fileURL);
        });

Service 服务

var reportUrl = "http://192.168.8.87/api/report";
    var _print = function (parameter) {
        return $http.post(reportUrl, parameter, { responseType: 'arraybuffer' }).success(function (response) {
            return response;
        });
    };

The main idea is that the result.data is converted into a blob and create an objectURL so that it is readable and to the object tag and $sce.trustAsResourceUrl used to trust angular to your URL 主要的想法是将result.data转换为blob并创建一个objectURL ,使其可读并且object标签和$sce.trustAsResourceUrl用于信任您的URL角度

HTML HTML

<object data="{{content}}" type="application/pdf" style="width:100%;height:80%"></object>

I refer to this post AngularJS: Display blob (.pdf) in an angular app for clarification just read that one. 我在这篇文章中提到AngularJS:在角应用程序中显示blob(.pdf),以便澄清一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM