So I'm trying to get the camera to take a picture and display it in img tag, simple enough right ? Everything seems fine, I'm able to take a picture and the URI is printed, but I'm getting an error on $scope.$apply(). I'm running it on Android 4.4.4. Here's my code:
.controller("TakePictureController", function($scope, Camera) {
$scope.getPhoto = function() {
Camera.getPicture().then(function(imageURI) {
$scope.src = imageURI;
$scope.$apply();
console.log(imageURI);
}, function(err) {
console.log(err);
});
};
});
.factory('Camera', ['$q', function($q) {
return {
getPicture: function(options) {
var q = $q.defer();
navigator.camera.getPicture(function(result) {
q.resolve(result);
}, function(err) {
q.reject(err);
}, options);
return q.promise;
}
}
}])
and the HTML:
<ion-content class="padding">
<button class="button button-full button-positive" ng-click="getPhoto()">
Take pic
</button>
<img ng-src="{{src}}">
</ion-content>
This is what I get in the console as URI:
file:///storage/sdcard0/Android/data/com.ionicframework.overtredingbe668924/cache/1437826221441.jpg
This is the error I get:
12 237093 error Error: [$rootScope:inprog] $digest already in progress
http://errors.angularjs.org/1.3.13/$rootScope/inprog?p0=%24digest
I tried putting this in
if(!$scope.$$phase) {
$scope.$apply();
}
I don't get the error anymore, but picture is not shown. Any advice ?