为什么qr代码扫描的插件cordova不起作用?

时间:2016-08-11 21:26:58

标签: angularjs cordova ionic-framework ngcordova

我必须开发一个可以进行二维扫描的应用程序,但我的代码不起作用。我已经安装了ngco​​rdova和插件以及相机的插件。以下错误不断弹出。

错误:

?ionicplatform=android:28 ReferenceError: cordova is not defined
    at Object.scan (ng-cordova.min.js:7)
    at controllers.js:10
    at ionic.bundle.js:56230
    at Object.ready (ionic.bundle.js:2140)
    at Object.ready (ionic.bundle.js:56223)
    at Scope.$scope.scan (controllers.js:9)
    at fn (eval at compile (ionic.bundle.js:27638), <anonymous>:4:203)
    at ionic.bundle.js:65427
    at Scope.$eval (ionic.bundle.js:30395)
    at Scope.$apply (ionic.bundle.js:30495)

HTML:

<!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
        <title></title>

        <link href="lib/ionic/css/ionic.css" rel="stylesheet">
        <link href="css/style.css" rel="stylesheet">

        <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
        <link href="css/ionic.app.css" rel="stylesheet">
        -->

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

        <!-- cordova script (this will be a 404 during development) -->
        <script src="cordova.js"></script>
        <script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
        <!-- your app's js -->
        <script src="js/app.js"></script>
        <script src="js/controllers.js"></script>
      </head>

      <body ng-app="starter">
        <ion-nav-view></ion-nav-view>
      </body>
    </html>

控制器:

    angular.module('starter.controllers', ['ngCordova'])
    .controller('AppCtrl', function($scope, $ionicModal, $timeout) {

    })
    .controller('PlaylistsCtrl', function($scope, $ionicPlatform,
    $cordovaBarcodeScanner) {
      $scope.scan = function(){
        $ionicPlatform.ready(function() {
          $cordovaBarcodeScanner.scan().then(function(barcodeData) {
            // Success! Barcode data is here
          }, function(error) {
       // An error occurred
        });
      });
     };
    })

感谢任何帮助!

0 个答案:

没有答案