[英]How to connect jsReport in AngularJS?
我現在有一個關於JSReport的問題..它假設我已經有了一個API ...我現在想要的是如何將它與我使用AngularJS的客戶端鏈接。
如果我使用Postman,它將返回一個我想要的pdf文件。 但我的問題是當我使用angularjs發布它時如何顯示它是我的頁面..
我有這樣的代碼:
調節器
$scope.Print = function () {
authService.print().then(function(result){
var _result = result;
});
};
服務
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;
現在我有了這個代碼並且它不起作用......我認為它沒有返回所以我刪除了返回並且只是發布但是它仍然沒有用,甚至下載pdf也沒有用。
有人可以幫忙嗎...
像這樣使用..
調節器
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);
});
服務
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;
});
};
主要的想法是將result.data
轉換為blob並創建一個objectURL
,使其可讀並且object
標簽和$sce.trustAsResourceUrl
用於信任您的URL
角度
HTML
<object data="{{content}}" type="application/pdf" style="width:100%;height:80%"></object>
我在這篇文章中提到AngularJS:在角應用程序中顯示blob(.pdf),以便澄清一下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.