我点击了这个链接 Ionic 2 文件插件使用示例拍照并将其存储到我内部存储器内的目标文件夹中,我测试了它工作正常,接下来我试图列出该文件夹中的所有文件,我完成了,但我无法查看它,
<ion-list>
<ion-item><img [src]="file" *ngFor="let file in myFiles"></ion-item>
</ion-list>
import { Component } from '@angular/core';
import { NavController, AlertController, ActionSheetController, ToastController, Platform, LoadingController, Loading } from 'ionic-angular';
import { Camera } from 'ionic-native';
import { File } from 'ionic-native';
import { FilePath } from 'ionic-native';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
file;
public base64Image: string;
myFiles: string[];
constructor(public navCtrl: NavController,
public alertCtrl: AlertController){}
listImage(){
console.log("list image files");
var fileSystem = cordova.file.externalRootDirectory;
var folderpath = fileSystem + "Vanan Audio/";
console.log("img",folderpath);
File.listDir(cordova.file.externalRootDirectory, 'vanan Audio').then(
(allFiles) => {
// do something
console.log(allFiles);
var i =0
console.log(allFiles[i+1].name);
for (i = 0; i < allFiles.length; i++) {
console.log(allFiles[i].name);
console.log(allFiles[i].nativeURL);
}
this.myFiles = allFiles;
return allFiles
}
).catch(
(err) => {
// do something
}
);
}
}
现在我可以拍照并使用外部根目录将其存储到文件夹中,我可以使用循环列出文件名,我需要将该文件夹中的所有图像显示到我的离子视图
当我在我的设备上运行它时,我有一个获取错误语句
deviceready has not fired after 5 seconds. cordova.js:1223
Unhandled Promise rejection: Template parse errors:
Can't bind to 'ngForIn' since it isn't a known property of 'div'. ("
<div [ERROR ->]*ngFor="let file in myFiles">
<img [src]="file.nativeURL"/>
"): HomePage@28:9.............................
在组件中有一个文件路径数组:
myFiles:any[];//assign empty array in constructor
在File.listDir then
中(假设listImage()
在组件中(:
this.myFiles = allFiles;
在 html 中,
<div *ngFor="let file of myFiles">
<img [src]="file.nativeURL"/>
</div>