我正嘗試構建一個離子應用程序,用戶在單擊鏈接時在其設備上打開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不太熟悉。如果您需要查看我的其他文件,請告訴我。
添加ngCordova和模塊需要$ cordovaFileOpener2Provider –