Cordova摄像头和Ionic Framework-控制器和Index.html未连接
我正在尝试用Ionic Framework和Cordova实现一个摄像头应用程序,并努力理解为什么它会抛出以下错误,从而无法实例化摄像头:Cordova摄像头和Ionic Framework-控制器和Index.html未连接,cordova,camera,ionic-framework,ionic,cordova-plugins,Cordova,Camera,Ionic Framework,Ionic,Cordova Plugins,我正在尝试用Ionic Framework和Cordova实现一个摄像头应用程序,并努力理解为什么它会抛出以下错误,从而无法实例化摄像头: 0 444468 error Uncaught SyntaxError: Unexpected token ., http://192.168.0.10:8100/js/app.js, Line: 9 1 444540 error Uncaught Error: [$injector:moduler
0 444468 error Uncaught SyntaxError: Unexpected token ., http://192.168.0.10:8100/js/app.js, Line: 9
1 444540 error Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to:
Error: [$injector:nomod] Module 'starter' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
不幸的是,以下问题和答案没有帮助我回答我的问题:
我参考了以下教程来完成这项工作,但没有成功(有时我会更加困惑):
index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
<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>
</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-assertive">
<h1 class="title">Title of App</h1>
</ion-header-bar>
<ion-content ng-controller="CameraCtrl">
<div class="list card"
<div class="item item-image">
<img ng-src="{{pictureUrl}}">
</div>
</div>
<div class="padding">
<button ng-click="takePicture()"
class="button button-block button-assertive">Take a Photo</button>
</div>
</ion-content>
</ion-pane>
</body>
</html>
提前感谢您的帮助
angular.module('starter', ['ionic', 'ngCordova']);
这就是你的错误所在,那里不应该有分号
它的angular.module('moduleName').controller('controllerName',function(){})代码>
这就是你的错误所在,那里不应该有分号
它的angular.module('moduleName').controller('controllerName',function(){})代码>是正确的
我将在这里回答,即使这应该是一个评论,因为我没有足够的空间
你有两个选择。您可以定义要在模块(app.js)中使用的变量:
并使用app变量:
app.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
});
app.controller('CameraCtrl', function($scope, $cordovaCamera) {
...
});
或移除半柱:
angular.module('starter', ['ionic', 'ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.controller('CameraCtrl', function($scope, $cordovaCamera) {
...
});
这是对的
我将在这里回答,即使这应该是一个评论,因为我没有足够的空间
你有两个选择。您可以定义要在模块(app.js)中使用的变量:
并使用app变量:
app.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
});
app.controller('CameraCtrl', function($scope, $cordovaCamera) {
...
});
或移除半柱:
angular.module('starter', ['ionic', 'ngCordova'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.controller('CameraCtrl', function($scope, $cordovaCamera) {
...
});
尽管您建议进行修复,但现在仍出现以下错误0 830977 error Uncaught SyntaxError:意外标记:,http://192.168.0.10:8100/js/app.js,第16行:1 831058错误未捕获错误:[$injector:modulerr]未能实例化模块启动器,原因是:错误:[$injector:nomod]模块“启动器”不可用!您要么拼错了模块名,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。
您要求我修复的代码现在看起来是这样的angular.module('starter'['ionic','ngCordova'])。controller('CameraCtrl',function($scope,$cordovaCamera)
@stefbmt检查下面的答案,我错过了.controller声明末尾的分号,这就是为什么您仍然会出现此错误。很抱歉,麻烦!尽管您提出了修复方案,但现在出现了以下错误0 830977错误未捕获语法错误:意外标记:,http://192.168.0.10:8100/js/app.js,第16行1 831058错误未捕获错误:[$injector:modulerr]未能实例化模块启动器,原因是:错误:[$injector:nomod]模块“starter”不可用!您可能拼错了模块名称或忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。
您要求我修复的代码现在看起来是这样的angular.Module('starter'['ionic','ngCordova'])。controller('Cameracrl',function($scope$cordovaCamera)
@stefbmt检查下面的答案,我错过了.controller声明末尾的分号,这就是为什么您仍然会遇到此错误。很抱歉!100%正确,我错过了.controller声明末尾的分号,这就是为什么会显示其他错误!太好了clarification@JadSalhani当前位置是的,我的只是一本书您的答案是正确的,但是:-)100%正确,我错过了.controller声明末尾的分号,这就是为什么显示其他错误的原因!太好了clarification@JadSalhani:是的,我只是澄清一下。不过,你的回答很好:-)