android - 如何使用 Ionic 3 将文本文件的内容作为字符串获取?

标签 android typescript ionic-framework ionic3

我试过这个:

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 + "<");

但是我进入了 logcat:

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

这个项目是:

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

最佳答案

这是因为 readAsText 返回一个 promise 。你应该这样做

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

关于android - 如何使用 Ionic 3 将文本文件的内容作为字符串获取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44820961/

相关文章:

TypeScript:将拒绝的 promise 作为参数传递

javascript - Ion slide box - 如何在 ion slide 中滑动全宽 iframe 视频

android - 显存和安卓应用

安卓工作室 : What is the right way to change targetSdkVersion?

Android 更改应用程序名称和 Logo

android - 使用 Android MediaPlayer 播放声音时出现问题

typescript - vscode-jest 在 typescript 源文件中带有 ts-jest 断点

angular - 在 ngOnInit 中测试一个可观察的间隔

angular - 'ion-tab' 不是已知元素

angularjs - window.plugins.AdMob 在 ionic 应用程序中始终未定义