无法通过cordovaplugin捕获图像来查看图像

时间:2017-02-06 03:46:45

标签: ionic2 cordova-plugins

我按照此链接Ionic 2 File Plugin usage examples拍照并将其存储到我内部存储器内的目标文件夹中,我测试它运行良好,接下来我试图列出该文件夹中的所有文件我做了但是我无法看到它,

<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.............................

1 个答案:

答案 0 :(得分:0)

在组件中有一组文件路径:

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>