I selected the Ionic templates Tabs Application.
When I go into my camera app the button works fine on the initial tab that shows when the app starts.
If I put the button on the second or third tab, I can’t get the camera to work…
This is the code in the controller.js…
document.addEventListener(“deviceready”, onDeviceReady, false);
function id(element) {
return document.getElementById(element);
}
function onDeviceReady() {
cameraApp = new cameraApp();
cameraApp.run();
navigator.splashscreen.hide();
}
angular.module(‘starter.controllers’, [])
.controller(‘HomeCtrl’, function($scope) {
})
.controller(‘SoundsCtrl’, function($scope, Sounds) {
$scope.sounds = Sounds.all();
})
.controller(‘SoundsDetailCtrl’, function($scope, $stateParams, Sounds) {
$scope.sound = Sounds.get($stateParams.soundId);
})
.controller(‘CameraCtrl’, function($scope) {
$scope.getPhoto = function() {
Camera.getPicture().then(function(imageURI) {
console.log(imageURI);
$scope.lastPhoto = imageURI;
}, function(err) {
console.err(err);
}, {
quality: 75,
targetWidth: 320,
targetHeight: 320,
saveToPhotoAlbum: false
});
};
});
function cameraApp(){}
cameraApp.prototype={
_pictureSource: null,
_destinationType: null,
run: function(){
var that=this;
that._pictureSource = navigator.camera.PictureSourceType;
that._destinationType = navigator.camera.DestinationType;
id(“capturePhotoButton”).addEventListener(“click”, function(){
that._capturePhoto.apply(that,arguments);
});
},
_capturePhoto: function() {
var that = this;
//ADD PLAY SOUND HERE
//that._onPhotoDataSuccess.apply(that,arguments);
// Take picture using device camera and retrieve image as base64-encoded string.
//navigator.camera.getPicture().then(function(imageURI) {},
navigator.camera.getPicture(function(){
},function(){
that._onFail.apply(that,arguments);
},{
quality: 50,
destinationType: that._destinationType.DATA_URL
});
},
}
Thank you,
Pete