I am looking for a solution to display a document in a mobile application I am developing using AngularJS and Cordova/Phonegap.
I am using a Web Service that returns the raw content for a file, so for example I use my AngularJS service to use the Web Service to get a file, what it returns is the raw content of the file. In the case I show below it is a Word document. But it could be PDF, Excel, Powerpoint etc...
I am relatively new to AngularJS and with only some experience with HTML and Javascript I am looking for guidance on the best approach to use the raw data from the web service to display the document inline in my application.
Below is my current code and an image from my device to show what I am currently getting. My question is what is my best approach from here to get the document to a viewable state in the application?
My service:
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;
}
}
}]);
My Controller:
myApp.controllers.controller("DownloadDocCtrl", ['$scope', 'DownloadDocService',
function ($scope, DownloadDocService) {
DownloadDocService.getDocument().then(function (document) {
$scope.document = document;
});
}
]);
My HTML:
<div style="color:#FFFFFF" ng-controller="DownloadDocCtrl">
{{document}}
</div>
Outcome: