2016-05-13 47 views
0

我正嘗試構建一個離子應用程序,用戶在單擊鏈接時在其設備上打開PDF。不過,我發現了以下錯誤鉻

ionic.bundle.js:25642 Error: [$injector:unpr] Unknown provider: 
$cordovaFileOpener2Provider <- $cordovaFileOpener2 <- FileOpenerController http://errors.angularjs.org/1.4.3/$injector/unpr?p0=%24cordovaFileOpener2Provider%20%3C-%20%24cordovaFileOpener2%20%3C-%20FileOpenerController 
    at ionic.bundle.js:13380 
    at ionic.bundle.js:17574 
    at Object.getService [as get] (ionic.bundle.js:17721) 
    at ionic.bundle.js:17579 
    at getService (ionic.bundle.js:17721) 
    at Object.invoke (ionic.bundle.js:17753) 
    at extend.instance (ionic.bundle.js:22311) 
    at nodeLinkFn (ionic.bundle.js:21421) 
    at compositeLinkFn (ionic.bundle.js:20853) 
    at compositeLinkFn (ionic.bundle.js:20857)(anonymous function) @ ionic.bundle.js:25642(anonymous function) @ ionic.bundle.js:22421processQueue @ ionic.bundle.js:27887(anonymous function) @ ionic.bundle.js:27895Scope.$eval @ ionic.bundle.js:29158Scope.$digest @ ionic.bundle.js:28969scopePrototype.$digest @ hint.js:1364Scope.$apply @ ionic.bundle.js:29263scopePrototype.$apply @ hint.js:1427done @ ionic.bundle.js:23676completeRequest @ ionic.bundle.js:23848requestLoaded @ ionic.bundle.js:23789 

這裏是我的app.js

angular.module('CCSD_Risk', ['ionic']) 

.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.overlaysWebView(true); 
     StatusBar.style(1); //Light 
    } 
    }); 
}); 

這是我的控制器main.js

console.log('main.js loaded'); 

angular.module('CCSD_Risk') 

.controller('mainCtrl', function($scope) { 
    $scope.helloWorld = function() { 
     console.log('helloWorld'); 
    }; 
}) 

.controller('FileOpenerController', function($scope, $cordovaFileOpener2, $ionicPlatform) { 
    console.log('hi 1'); 
    $scope.openPDF = function() { 
     console.log('hi'); 
     $cordovaFileOpener2.open(
      'flood-plans/cambeiro.pdf', // Any system location, you CAN'T use your appliaction assets folder 
      'application/pdf' 
     ).then(function() { 
      console.log('Success'); 
     }, function(err) { 
      console.log('An error occurred: ' + JSON.stringify(err)); 
     }); 
    }; 
}) 
.controller('TestController', function($scope) { 
    $scope.testConsole = function() { 
     console.log("this is a working controller"); 
    } 
}); 

我試着加入依賴ngCordova我的app.js文件,但這導致更多的錯誤發生。我不確定此時該做什麼。這是我嘗試用離子建立的第一個應用程序,我對angularJS不太熟悉。如果您需要查看我的其他文件,請告訴我。

+0

添加ngCordova和模塊需要$ cordovaFileOpener2Provider –

回答

0

在你app.js,添加ngCordova依賴: angular.module('CCSD_Risk', ['ionic', 'ngCordova']);

index.html中

,請確保您加入這一行: <script src="lib/ngCordova/ng-cordova.js"></script>

righ牛逼這個現有的一個以上: <script src="cordova.js"></script>

當然

,你需要有ng-cordova.jslib/ngCordova forder您的應用程序的

+0

這解決了我上面所得到的錯誤。但是,現在,無論何時點擊一個應該調用openPDF函數的鏈接,我都會得到一個cordova未定義的錯誤。 – SenorTiddlywinks

+0

這是因爲與cordova插件相關的功能僅在真實設備或模擬器上可用 –

+0

@Art Vandelay我需要幫助......我只是不能使它工作....我使用離子,但我不有一個文件ng-cordova.js如何獲取它? – lewis4u

相關問題