File opener 2 cordova plugin error in creator


#1

Hi,

I’m new to Creator and Angular and am mocking up a project in creator to use the file and file opener 2 cordova plugins as a service. Although I don’t expect it to work in preview mode, I am getting unexpected errors that I am not seeing when previewing with other cordova plugins (e.g. geolocation). The issue seems to be with the file opener 2 plugin. file plugin seems to work.

Here is the service:

angular.module(‘fileutils’, [])

.service(‘docViewer’, [’$cordovaFile’, ‘$cordovaFileOpener2’, function($cordovaFile, $cordovaFileOpener2) {

return {
view: function(docData, docName, mimeType){

    fetch(docData)
       .then(res => res.blob())
       .then(blob => 
             {
               $cordovaFile.writeFile(cordova.file.cacheDirectory, docName, blob, true)
                 .then(function (success) {
                     // success
                     $cordovaFileOpener2.open(cordova.file.cacheDirectory + docName, mimeType)
                       .then(function() {
                           // file opened successfully
                       }, function(err) {
                           // error
                           alert('Error opening file [failed to read from ' + cordova.file.cacheDirectory + docName + ']');
                       });
                 }, function (error) {
                     // error
                     alert('Error opening file [failed to write to ' + cordova.file.cacheDirectory + docName + ']');
                 });  
             }
            ) // blob =>

    return true;
}

}

}]);

The error is:

ionic.bundle.js:26799 Error: [$injector:unpr] Unknown provider: $cordovaFileOpener2Provider <- $cordovaFileOpener2 <- docViewer
http://errors.angularjs.org/1.5.3/$injector/unpr?p0=%24cordovaFileOpener2Provider%20<-%20%24cordovaFileOpener2%20<-%20docViewer
at ionic.bundle.js:13443
at ionic.bundle.js:17793
at Object.getService [as get] (ionic.bundle.js:17946)
at ionic.bundle.js:17798
at getService (ionic.bundle.js:17946)
at injectionArgs (ionic.bundle.js:17970)
at Object.instantiate (ionic.bundle.js:18012)
at Object. (ionic.bundle.js:17855)
at Object.invoke (ionic.bundle.js:18000)
at Object.enforcedReturnValue [as $get] (ionic.bundle.js:17839)

I have added cordova-plugin-file and cordova-plugin-file-opener2 to Code Settings -> Cordova Plugins.