ios - Ionic and ngCordova FileOpener2 Plugin issue -
i building app ionic framework. , need ability open pdf. using ngcordova plugin fileopener2
task.
i no error , success message prompted shows.
this controller :
module.controller('newsctrl', function ($cordovafileopener2) { $cordovafileopener2.open( '../img/newsletter.pdf', 'application/pdf' ).then(function() { console.log('success'); }, function(err) { console.log('error' + err ); }); });
i running in emulator command ionic emulate ios --livereload --target="iphone-4s"
i have tested in actual device similar results.
i did stumble upon error when changing of files , livereload server refreshing app on tab controller , got error :
error: undefined not object (evaluating 'cordova.plugins.fileopener2')
no need complicated plugin! in our company app need able open pdf/s well. use https://github.com/sayanee/angularjs-pdf. works wonderfuly. here on android.
it works in ios: allows not have leave app open pdf. can pinch, zoom, rotate. here code looks like.
pdfviewer.html
<ion-view> <div class="bar bar-header bar-positive"> <button ng-click="$ionicgoback()" class="button button-clear button-light icon-left ion-chevron-left">go back</button> </div> <div class="has-header"> <ng-pdf template-url="components/pdfviewer/viewer.html" canvasid="pdf" scale="0.675"> </ng-pdf> </div> </ion-view>
viewer.html
<div ng-show="notloaded" class=" center bar bar-subheader"> <h1 class="title">loading pdf...</h1> </div> <div class="tabs tabs-icon-left"> <a class="tab-item" ng-click="goprevious()"> <i class="icon ion-arrow-left-c"></i> prev </a> <a class="tab-item" ng-click="gonext()"> <i class="icon ion-arrow-right-c"></i> next </a> </div> <ion-scroll zooming="true" direction="xy" class="has-header"> <canvas class="padding" id="pdf" class="rotate0"></canvas> </ion-scroll>
viewer.controller.js
//variable shows , hides pdf loading bar $scope.notloaded = true; //grabs pdfurl $scope.pdfurl = ffservice.pdflink; //sets position of pdf viewer controls $scope.getnavstyle = function (scroll) { if (scroll > 100) return 'pdf-controls fixed'; else return 'pdf-controls'; }; //do on pdf progress $scope.onprogress = function (progress) { } //do once pdf loaded, use show , hide //the loading... header on android $scope.onload = function () { $scope.notloaded = false; } //error logger pdf viewer $scope.onerror = function (error) { $scope.showcustomalert('something went wrong', '<div class="center">' + error + '</div>'); };
and include js file in html , inject 'pdf' top level module
angular.module('ffapp', ['ionic', 'controllers', 'services', 'ngcordova', 'pdf', 'ngsanitize', 'ngimgcrop', 'chart.js', 'ionic.service.core', 'ionic.service.push']);
Comments
Post a Comment