我收到此错误并一直在谷歌上寻找它但仍无法解决此问题。
ionic.bundle.js:26799 Error: [$injector:unpr] Unknown provider: $cordovaCameraProvider <- $cordovaCamera <- CameraCtrl
下面给出的app.js代码
angular.module('starter', ['ionic','ng-Cordova','starter.controllers', 'starter.services'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
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();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'templates/tabs.html'
})
.state ('camera',{
url:'/camera',
controller:'CameraCtrl'
})
.state('tab.account', {
url: '/done',
views: {
'tab-d': {
templateUrl: 'templates/d.html',
controller: 'DCtrl'
}
}
});
$urlRouterProvider.otherwise('/abc');
});
下面给出的Controller.js代码
.controller('CameraCtrl', function($scope, $cordovaCamera) {
document.addEventListener("deviceready", function () {
var options = {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 100,
targetHeight: 100,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation:true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}, function(err) {
// error
});
}, false);
})
单击此图标时,应打开相机以捕获图像
<a href="#/camera"><i class="icon ion-camera"></i></a>
答案 0 :(得分:1)
在 app.js 中,您应该更改此行
// Connects the text boxes to the collaborative string
function wireTextBoxes(collaborativeString) {
var textArea1 = document.getElementById('text_area_1');
var textArea2 = document.getElementById('text_area_2');
var myCodeMirror = CodeMirror.fromTextArea(textArea1); // duh
gapi.drive.realtime.databinding.bindString(collaborativeString, textArea1);
gapi.drive.realtime.databinding.bindString(collaborativeString, textArea2);
}
到这个
angular.module('starter', ['ionic','ng-Cordova','starter.controllers', 'starter.services'])
ngCordova docs中的更多相关内容:
注入角色依赖
angular.module('starter', ['ionic','ngCordova','starter.controllers', 'starter.services'])
答案 1 :(得分:-1)
我通过以下步骤解决了这个问题:
第1步:使用bower安装ngCordova
$ bower install ngCordova --save
步骤2:在cordova.js之前和之后的AngularJS / Ionic文件中包含ng-cordova.js或ng-cordova.min.js(因为ngCordova依赖于AngularJS) )。
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
第3步:然后,在角度模块中包含ngCordova作为依赖项:
angular.module('myApp', ['ngCordova'])