我无法使用$ cordovaFileOpener2来处理我的离子应用程序。

时间:2016-05-13 18:54:31

标签: javascript android ios angularjs ionic-framework

我正在尝试构建一个离子应用,用户在点击链接时会在用户的设备上打开PDF。但是,我在chrome中遇到以下错误

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不太熟悉。如果您需要查看我的其他任何文件,请通知我。

2 个答案:

答案 0 :(得分:0)

结帐

error discusstion link  和 解 pluging

答案 1 :(得分:0)

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

在index.html中

,请确保添加以下行: <script src="lib/ngCordova/ng-cordova.js"></script>

正好位于现有的位置之上: <script src="cordova.js"></script>

当然,您需要ng-cordova.js for lib/ngCordova forder