[solved] file.externalDataDirectory is sometimes null but sometimes not


#1

I have this code:

constructor(private file: File) {}

ngOnInit(){
    console.log(this.file.externalDataDirectory);

    var filesDirectory = this.file.externalDataDirectory;
    this.file.readAsText(filesDirectory, 'songs.json')
        .then((text) => {
          let jsonObj: any = JSON.parse(text);
          this.loadSongs(jsonObj);  
        })
        .catch(error => {
          console.log(error.error);
        }); 
  }

in like 50% of the times I run the app, the console log for file.externalDataDirectory gives me “null”, and the other 50% it gives the right path. why is that happening?
the times it is “null” the rest of the function doesn’t not work saying “Expected String, but got Null.”

I’m running it on an android device

edit:
oops. sorry guys, I forgot to perform the platform.ready() check, that was the problem. the case is solved. my bad.