所以我试图让相机拍照并用img标签显示,这很简单吗?一切似乎都很好,我能够拍照并打印URI,但我在$ scope上收到错误。$ apply()。我在Android 4.4.4上运行它。这是我的代码:
CPUUsage
和HTML:
.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;
}
}
}])
这是我在控制台中获得的URI:
<ion-content class="padding">
<button class="button button-full button-positive" ng-click="getPhoto()">
Take pic
</button>
<img ng-src="{{src}}">
</ion-content>
这是我得到的错误:
file:///storage/sdcard0/Android/data/com.ionicframework.overtredingbe668924/cache/1437826221441.jpg
我尝试将其放入
12 237093 error Error: [$rootScope:inprog] $digest already in progress
http://errors.angularjs.org/1.3.13/$rootScope/inprog?p0=%24digest
我不再收到错误,但图片未显示。有什么建议吗?