2017-09-23 4 views
0

디렉터리에서 모든 파일을 반복적으로 읽어야합니다.클래스 멤버 변수가 정의되지 않았습니다.

import { Component } from '@angular/core'; 
import { File } from '@ionic-native/file' 

@Component({ 
    selector: 'page-files', 
    templateUrl: 'files.html', 
}) 
export class FilesPage { 

    public filePaths: string[]; 

    constructor(private file: File) { 
    } 

    ionViewDidLoad() { 
    this.findFiles("WhatsApp/Media"); 
    } 

    findFiles(dir: string): void { 

    this.file.listDir(this.file.externalRootDirectory, dir).then(
     (files) => { 
     for (let file of files) { 
      if (file.isDirectory && file.name != '.' && file.name != '..') { 
      this.findFiles(dir + "/" + file.name) 
      } else { 
      this.filePaths.push(file.name) 
      } 
     } 
     } 
    ).catch(
     (err) => { 
     console.log(err.toString()) 
     } 
    ); 
    } 
} 

내가 런타임 오류가 무엇입니까 this.findFiles(dir: string): void 사용할 수 this.filePaths.push(file.name)

그러나 멤버 함수에서 무슨 일이 없습니다 "this.filePaths하는 정의되지 않는다"

가 나는 코드를 사용 this.filePaths 멤버 변수.

답변

0

filePaths는 정의되지 않았습니다. 생성자에서 변수를 인스턴스화하려고 시도하십시오.

this.filePaths = [];