Hi Guys,
I am trying achieve building an app that content will be manage via json file, where everything the user opens the app and has internet connection it will check if the json file on our website is has been updated and will download it and will be used by the app for data and content of all pages.
However right now a the error below when running emulate ios…
I have follow the instruction from https://ionicframework.com/docs/native/file-transfer/ and i am stuck…
[00:14:53] typescript: src/pages/home/home.ts, line: 115
A class member cannot have the 'const' keyword.
L115: const fileTransfer: FileTransferObject = this.transfer.create();
[00:14:53] typescript: src/pages/home/home.ts, line: 121
Cannot find name 'fileTransfer'. Did you mean the instance member 'this.fileTransfer'?
L120: const url = 'http://www.example.com/file.pdf';
L121: fileTransfer.download(url, this.file.dataDirectory + 'file.pdf').then((entry) => {
L122: console.log('download complete: ' + entry.toURL());
[00:14:53] typescript: src/pages/home/home.ts, line: 123
'error' is declared but never used.
L122: console.log('download complete: ' + entry.toURL());
L123: }, (error) => {
L124: // handle error
I have this in my home.ts
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer';
import { File } from '@ionic-native/file';
constructor(private transfer: FileTransfer, private file: File) { }
const fileTransfer: FileTransferObject = this.transfer.create(); <-- this one is causing the error
public download() {
const url = 'http://www.example.com/file.pdf';
fileTransfer.download(url, this.file.dataDirectory + 'file.pdf').then((entry) => {
console.log('download complete: ' + entry.toURL());
}, (error) => {
// handle error
});
}
ionViewDidLoad() {
console.log('ionViewDidLoad HomePage');
this.download();
}
and i have also import in my app.module.ts
import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer';
import { File } from '@ionic-native/file';
providers: [
![26 AM|572x499](upload://xvuECYHTd8PhZwHo8i73a9ihrIa.png)
{ provide: ErrorHandler, useClass: IonicErrorHandler }
]
I hope someone can help me out with this, and thanks in advance.