2016-04-20 7 views
0

EDIT speichern: Macht nichts. Ich reparierte sie durch erneute Zugabe von Plattformen:Versuchen, ein pdf lokal auf dem Gerät mit ngCordova

1) ionische Plattform rm android

2) ionische Plattform hinzufügen android

.......

Ich versuche zu retten eine pdf mit ngcordova plugin $ cordovaFile. Aber ich erhalte eine Fehlermeldung:

Uncaught Reference: $ cordovaFile nicht definiert ist, http://192.168.149.151:8100/js/invoice.service.js, Zeile: 16

ich das Plugin installiert ist, enthalten das Skript in index.html, den gleichen Fehler in Browser bekommen und auf dem Gerät . Fehle ich etwas?

app.js:

var exampleApp = angular.module('starter', ['ionic','pdf','ngCordova']) 

.run(function($ionicPlatform) { 
$ionicPlatform.ready(function() { 


if(window.cordova && window.cordova.plugins.Keyboard) { 
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
    // for form inputs) 
    cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 

    // Don't remove this line unless you know what you are doing. It stops the viewport 
    // from snapping when text inputs are focused. Ionic handles this internally for 
    // a much nicer keyboard experience. 
    cordova.plugins.Keyboard.disableScroll(true); 
} 
if(window.StatusBar) { 
    StatusBar.styleDefault(); 
} 
}); 
}); 

index.html:

<!-- ionic/angularjs js --> 
<script src="lib/ionic/js/ionic.bundle.js"></script> 

<!-- cordova script (this will be a 404 during development) --> 
<script src="lib/ngCordova/dist/ng-cordova.js"></script> 
<script src="cordova.js"></script> 

Service:

angular.module('starter').factory('InvoiceService', ['$q', InvoiceService]); 

function InvoiceService($q) { 
function createPdf(invoice) { 
    return $q(function(resolve, reject) { 
     var dd = createDocumentDefinition(invoice); 
     var pdf = pdfMake.createPdf(dd); 

     pdf.getBase64(function (output) { 
      resolve(base64ToUint8Array(output)); 
     }); 
     pdfMake.createPdf(dd).getBuffer(function (buffer) { 
     var utf8 = new Uint8Array(buffer); // Convert to UTF-8... 
     binaryArray = utf8.buffer; // Convert to Binary... 

     $cordovaFile.writeFile(cordova.file.dataDirectory, "example.pdf", binaryArray, true) 
     .then(function (success) { 
     console.log("pdf created"); 
     }, function (error) { 
     console.log("error"); 
     }); 
     }); 
    }); 
} 

return { 
    createPdf: createPdf 
};  
} 

Plugin-Liste:

ionic plugin list 
com.jcjee.plugins.emailcomposer 1.4.6 "Email Composer with Attachments" 
cordova-plugin-console 1.0.2 "Console" 
cordova-plugin-device 1.1.1 "Device" 
cordova-plugin-file 4.1.1 "File" 
cordova-plugin-splashscreen 3.2.1 "Splashscreen" 
cordova-plugin-statusbar 2.1.2 "StatusBar" 
cordova-plugin-whitelist 1.2.1 "Whitelist" 
ionic-plugin-keyboard 2.0.1 "Keyboard" 
dms-MacBook-Pro:pdf-test dms$ ionic plugin list 
com.jcjee.plugins.emailcomposer 1.4.6 "Email Composer with Attachments" 
cordova-plugin-console 1.0.2 "Console" 
cordova-plugin-device 1.1.1 "Device" 
cordova-plugin-file 4.1.1 "File" 
cordova-plugin-splashscreen 3.2.1 "Splashscreen" 
cordova-plugin-statusbar 2.1.2 "StatusBar" 
cordova-plugin-whitelist 1.2.1 "Whitelist" 
ionic-plugin-keyboard 2.0.1 "Keyboard" 

Antwort

0

Macht nichts. Ich reparierte sie durch erneute Zugabe von Plattformen:

1) ionische Plattform rm android

2) ionische Plattform hinzufügen android

0

Sie verwenden ‚$ cordovaFile‘ in der Fabrik, aber sie injizieren nicht, dass Ihre Fabrik/Servicemodul sollte wie folgt sein:

angular.module('starter').factory('InvoiceService', ['$q', InvoiceService, '$cordovaFile', function($q,InvoiceService,$cordovaFile) {}]); 

Oder

angular.module('starter').factory("InvoiceService", function($q,InvoiceService,$cordovaFile) {}); 
Verwandte Themen