MrFlyingToasterman
MrFlyingToasterman

Reputation: 227

How can I use Ionic 3 to get the content of a text file as a string?

I tried this:

this.item = this.params.get('filename');
console.log("[INFO] Opening File: >" + this.item + "<");
this.textboxContent = this.file.readAsText(this.file.dataDirectory, this.item);
console.log("[INFO] Content of textboxContent: >" + this.textboxContent + "<");

But i get in logcat:

[INFO:CONSOLE(56865)] "[INFO] Content of textboxContent: >[object Promise]<"

this.item is:

[INFO:CONSOLE(56863)] "[INFO] Opening File: >SomeFile.txt<"

Upvotes: 1

Views: 1030

Answers (1)

Saksham Gupta
Saksham Gupta

Reputation: 628

This is because readAsText returns a promise. You should do this instead

this.file.readAsText(this.file.dataDirectory, this.item).then((content)=>  
{
  this.textboxContent = content;
})

Upvotes: 2

Related Questions