我想拍摄不同元素的照片或为一件元素拍摄多张照片,但我正在努力弄清楚如何将图像推送到数组中。
从第一行开始显示单个图像:
<img ng-show="imgURI !== undefined" ng-src="{{imgURI}}" style="text-align: center">
但是使用ng-repeat
它不会显示一张图像。
我怀疑我的问题是:
- 我的 ng-repeat 有什么问题吗?
- 图像实际上是否正确存储在数组内?
HTML
<button class="button button-full button-assertive" ng-click="takePhoto()">
Take Photo
</button>
<img ng-show="imgURI !== undefined" ng-src="{{imgURI}}" style="text-align: center">
<ion-item class="item item-assertive">Test array</ion-item>
<div ng-repeat="x in array">
<img ng-src="{{x.imgURI}}">
</div> center">
Javascript
$scope.takePhoto = function () {
var options = {
quality: 75,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 300,
targetHeight: 300,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
};
$scope.array = [];
$cordovaCamera.getPicture(options).then(function (imageData) {
$scope.imgURI = "data:image/jpeg;base64," + imageData;
$scope.imgURI = array;
}, function (err) {
// An error occured. Show a message to the user
});
}
最佳答案
您正在将 imageUri 设置为数组的值。
$scope.imgURI = ar;
我想你想像这样对数组进行推送:
$scope.array.push($scope.imgURI);
关于javascript - 将图像插入数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37674782/