this code returns:
此代码返回:
Cannot read property 'getPicture' of undefined
Have no idea what im doing wrong, can you please help me with the code?
不知道我做错了什么,你能帮我解决一下代码吗?
My App:
我的应用:
angular.module('Todo', ['ionic', 'Todo.controllers','ngStorage', 'Todo.services', 'ngCordova'])
angular.module('Todo',['ionic','Todo.controllers','ngStorage','Todo.services','ngCordova'])
my Controller:
我的控制器:
.controller('profileEditCtrl', function($scope,Camera, $localStorage,
$cordovaCamera)
{
$scope.$storage = $localStorage.$default({ data:[]});
$scope.takePicture = function()
{
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.DATA_URL });
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src ="data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('Failed because: ' + message);
}
}});
12
Your code is correct, just add an html button with ng-click="takePicture()"
.
你的代码是正确的,只需添加一个带有ng-click =“takePicture()”的html按钮。
There is no problem here, It's sure that the browser "cannot read property 'getPicture' of undefined"
because it has no configuration for a mobile camera that you defined, which means you should test your application on a real device using:
这里没有问题,确定浏览器“无法读取未定义的属性'getPicture',因为它没有为您定义的移动相机配置,这意味着您应该使用以下方法在真实设备上测试您的应用程序:
> ionic run android
.
>离子运行android。
Notice that the new update of Google Chrome has a new feature which helps your test your device on the browser if it is connected to the PC/laptop, for testing go to chrome's navigation panel >> More tools >> Inspect devices or just go to this link:
请注意,谷歌浏览器的新更新有一项新功能,可以帮助您在浏览器上测试设备,如果它连接到PC /笔记本电脑,测试转到chrome的导航面板>>更多工具>>检查设备或只是去这个链接:
chrome://inspect/#devices
铬://检查/#设备
I'm sure your camera will function normally if you have the plugin cordova plugin add org.apache.cordova.camera
installed in the app,
I hope this helps you.
如果您在应用程序中安装了插件cordova插件添加org.apache.cordova.camera,我相信您的相机将正常运行,我希望这对您有所帮助。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2014/07/26/5cfc96b6ac2767161b6c296d704db4a9.html。