我正在寻找一种解决方案,以在我使用 AngularJS 和 Cordova/Phonegap 开发的移动应用程序中显示文档。
我正在使用返回文件原始内容的Web服务,因此例如我使用我的AngularJS服务来使用Web服务获取文件,它返回的是文件的原始内容。在下面我展示的例子中,它是一个 Word 文档。但它可以是 PDF、Excel、Powerpoint 等...
我对 AngularJS 比较陌生,只有一些 HTML 和 Javascript 经验,我正在寻找有关使用 Web 服务中的原始数据在我的应用程序中内联显示文档的最佳方法的指导。
下面是我当前的代码和来 self 的设备的图像,以显示我当前获得的内容。我的问题是,从这里让文档在应用程序中处于可查看状态的最佳方法是什么?
我的服务:
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;
}
}
}]);
我的 Controller :
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>
结果:
最佳答案
不,您必须有某种方法来解析文档。 DocX 实际上是一个巨大的 xml 文件,我非常确定,除非微软提供了一种使用 silverlight 来完成此操作的方法,否则它可能无法单独使用 Angular 来完成。
但是,您也许可以在您的 android 应用程序上使用一些 native 意图...或者您可以使用某些文档库编写自定义意图。我强烈推荐http://poi.apache.org/ .
这个答案:
以下是一些在创建此意向访问时可能有用的链接。用户可能需要对发出 .doc mimetype 的意图使用react的东西。但文档应该澄清其中的一些内容。
Is there an Intent for viewing documents (Word, Excel, Powerpoint, PDF, etc.) in Android?
http://devgirl.org/2013/07/17/tutorial-how-to-write-a-phonegap-plugin-for-android/
关于html - AngularJS - 我可以在 HTML 文件中显示文档吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24182616/