【发布时间】:2014-08-02 16:09:09
【问题描述】:
我正在寻找一种在我正在使用 AngularJS 和 Cordova/Phonegap 开发的移动应用程序中显示文档的解决方案。
我正在使用返回文件原始内容的 Web 服务,例如,我使用我的 AngularJS 服务来使用 Web 服务获取文件,它返回的是文件的原始内容。在我下面显示的情况下,它是一个 Word 文档。但它可以是 PDF、Excel、Powerpoint 等...
我对 AngularJS 比较陌生,并且只有一些 HTML 和 Javascript 经验,我正在寻找有关使用来自 Web 服务的原始数据在我的应用程序中内联显示文档的最佳方法的指导。
以下是我当前的代码和我设备中的图像,以显示我当前得到的内容。我的问题是从这里让文档在应用程序中处于可查看状态的最佳方法是什么?
我的服务:
myApp.services.factory('DownloadDocResource', ['$resource', function ($resource) {
return $resource('http://myWebSerivceURL/Documents/myTestDoc.doc', {}, {'query': {method: 'GET', isArray: false}});
}]);
myApp.services.factory('DownloadDocService', ['$q', 'DownloadDocResource', function($q, DownloadDocResource) {
return {
getDocument: function() {
var delay = $q.defer();
DownloadDocResource.query(
function (response) {
delay.resolve(response);
},
function (response) {
delay.reject("can't get document source");
});
return delay.promise;
}
}
}]);
我的控制器:
myApp.controllers.controller("DownloadDocCtrl", ['$scope', 'DownloadDocService',
function ($scope, DownloadDocService) {
DownloadDocService.getDocument().then(function (document) {
$scope.document = document;
});
}
]);
我的 HTML:
<div style="color:#FFFFFF" ng-controller="DownloadDocCtrl">
{{document}}
</div>
结果:
【问题讨论】:
标签: html angularjs cordova document angular-services