ReferenceError: cordova is not defined @ng-cordova.min.js:7
ReferenceError: cordova is not defined @ng-cordova.min.js:7
我是移动应用程序开发的新手。为了学习的目的,我构建了一个扫描条形码并显示文本的应用程序。
app.js
var app = angular.module('starter', ['ionic','ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
});
app.controller('ExampleController',function($scope,$cordovaBarcodeScanner){
$scope.scanBarcode = function () {
$cordovaBarcodeScanner.scan().then(function (imageData) {
alert(imageData.text);
},function (error) {
console.log(error);
});
}
});
index.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>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<script src="js/ng-cordova.min.js"></script>
</head>
<body ng-app="starter">
<ion-panel>
<ion-header-bar class="bar-stable">
<h1>Ionic Blank Starter</h1>
</ion-header-bar>
<ion-content ng-controller="ExampleController">
<button class="button" ng-click="scanBarcode()">Scan</button>
</ion-content>
</ion-panel>
</body>
</html>
当我按下按钮而不是打开相机时,返回此错误。
提前谢谢。
您需要在cordova.js文件之上包含ng-codova.min.js文件。
<!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="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
</head>
<body ng-app="starter">
<ion-panel>
<ion-header-bar class="bar-stable">
<h1>Ionic Blank Starter</h1>
</ion-header-bar>
<ion-content ng-controller="ExampleController">
<button class="button" ng-click="scanBarcode()">Scan</button>
</ion-content>
</ion-panel>
</body>
</html>
您可以通过ngCordova api的服务注入来使用它http://ngcordova.com/docs/plugins/statusbar/http://ngcordova.com/docs/plugins/keyboard/因为我相信你使用的var不存在。像在控制器中一样,在运行块中注入您使用的服务。
.run(function($ionicPlatform, $cordovaKeyboard, $cordovaStatusbar) {
$ionicPlatform.ready(function() {
$cordovaKeyboard.hideKeyboardAccessoryBar(true);
$cordovaKeyboard.disableScroll(true);
$cordovaStatusbar.styleDefault();
});
});
您可以用$ionicPlatform.ready()包围您的控制器扫描调用,因为您在控制器中编写的内容可以在准备好之前调用扫描低级别函数。
$scope.scanBarcode = function () {
$ionicPlatform.ready(function() {
$cordovaBarcodeScanner.scan().then(function (imageData) {
alert(imageData.text);
},function (error) {
console.log(error);
});
});
};
相关文章:
- jQuery-2.1.1.min.js或最新版本jQuery-2.13.min.js不会't支持'@
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- "TypeError:t.start未定义”;,在fullcalendar.min.js中,同时在我的网站上使
- 我应该担心HTML5Shiv.min.js 3.7.2版本上的这些JSLint警告吗?
- <script src=“//代码.jquery.com/jquery-1.11.1.min.js”></
- 加载less.min.js cdn会导致空白页面
- reactjs中为什么需要browser.min.js
- 使用jquery.chained.min.js链接选择不起作用
- angular.min.js:63 ReferenceError
- jquery.kyco.googleplusfeed.min.js未精简的源代码
- jquery.min.js版本冲突在asp.net网站中不起作用
- 把一个“;min.js”;MVC Bundles中的fil
- Foundation 5可能的错误:未捕获类型错误:层必须是文档节点Foundation.min.js:8
- 如何连接require.js与jquery.min.js
- bootstrap.min.css和bootstrap.min.js有什么区别
- 函数与 Jquery.min.js 冲突
- Kendo UI Complete (Trial) and Eclipse Juno: kendo.web.min.js
- 基金会.min.js在错误行中
- 使用 Grunt 创建 app.min.js 文件
- 错误:jQuery jquery.min.js?_=1420285687057:4 uncatch TypeError: