Я помещаю URL-адрес изображения в массив, после чего я не могу просмотреть изображение.
Я пробовал это для цикла, даже тогда я не могу это сделать ??
здесь я помещаю весь URL-адрес в массив для отображения на стороне клиента, но не могу его отобразить.
вот мой mutiupload.ts
import { Component } from '@angular/core';
import { AlertController ,NavController, ActionSheetController, ToastController, Platform, LoadingController, Loading, IonicPage } from 'ionic-angular';
import { File } from '@ionic-native/file';
import { Transfer, TransferObject } from '@ionic-native/transfer';
import { FilePath } from '@ionic-native/file-path';
import { Camera } from '@ionic-native/camera';
import { RestProvider } from '/home/bb/Desktop/root/frontend/css_client/src/providers/rest/rest';
declare var cordova: any;
/**
* Generated class for the MultiuploadPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-multiupload',
templateUrl: 'multiupload.html',
})
export class MultiuploadPage {
lastImage: string = null;
loading: Loading;
aImages : any;
constructor(public alertCtrl: AlertController ,public navCtrl: NavController, private camera: Camera, private transfer: Transfer, private file: File, private filePath: FilePath, public actionSheetCtrl: ActionSheetController, public toastCtrl: ToastController, public platform: Platform, public loadingCtrl: LoadingController,private auth: RestProvider) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad MultiuploadPage');
}
public presentActionSheet() {
let actionSheet = this.actionSheetCtrl.create({
title: 'Select Image Source',
buttons: [
{
text: 'Use Camera',
handler: () => {
this.takePicture(this.camera.PictureSourceType.CAMERA);
}
},
{
text: 'Cancel',
role: 'cancel'
}
]
});
actionSheet.present();
}
public takePicture(sourceType) {
// Create options for the Camera Dialog
var options = {
quality: 100,
sourceType: sourceType,
saveToPhotoAlbum: false,
correctOrientation: true
};
// Get the data of an image
this.camera.getPicture(options).then((imagePath) => {
// Special handling for Android library
var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
}, (err) => {
this.presentToast('Error while selecting image.');
});
}
// Create a new name for the image
private createFileName() {
var d = new Date(),
n = d.getTime(),
newFileName = n + ".jpg";
return newFileName;
}
// Copy the image to a local folder
private copyFileToLocalDir(namePath, currentName, newFileName) {
this.file.copyFile(namePath, currentName, cordova.file.dataDirectory, newFileName).then(success => {
this.lastImage = newFileName;
}, error => {
this.presentToast('Error while storing file.');
});
}
private presentToast(text) {
let toast = this.toastCtrl.create({
message: text,
duration: 3000,
position: 'top'
});
toast.present();
}
public pathForImage(img) {
if (img === null) {
return '';
} else {
var picture = cordova.file.dataDirectory + img;
this.aImages.push({
'image': picture
});
return picture;
}
}
} '
вот мой HTML-документ
<!--
Generated template for the MultiuploadPage page.
See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>
<ion-navbar color="primary">
<ion-title>multiupload</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<img src="{{pathForImage(lastImage)}}" style="width: 100%" [hidden]="lastImage === null">
<button ion-button primary (click) ="presentActionSheet()" ><ion-icon name="camera">Select</ion-icon></button>
</ion-content>
фактический результат должен быть массивом картинок, но я не могу показать картинку для предварительного просмотра.