Reputation: 71
Pls,pay attention to,the text file isn't in a www website(if it is in a web site ,I can use http request to get it ). I want to emphasize the store place of the file:before we run the "ionic cordova build android" the file is just under the directory of "src/asset/". just like the image below: in ionic project,and I have a.txt in the directory of "src/asset/"
after I run the command "ionic cordova build android ",and I get a android APK install file and the app run ok.I want to know,how do I can read a.txt in the app?I know the file is just in the apk,and I cann't get it.
Upvotes: 0
Views: 704
Reputation: 11
Please try something like this: Put this piece of code from where you want to access your file in your app.
return new Promise((resolve, reject) => {
this.http.get('assets/TempJobList.json')
.subscribe(res => {
resolve(res.json());
}, res => {
reject(res.json());
});
});
In your case "TempJobList.json" is the name of your text file.
Upvotes: 0