Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'dataDirectory' does not exist on type 'File'

Tags:

ionic4

I'm trying to use the FileTransfer Ionic 4 example.

I've performed the installation steps:

ionic cordova plugin add cordova-plugin-file
npm install @ionic-native/file

I've created a service:

import { Injectable } from '@angular/core';
import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer/ngx';
import { File } from '@ionic-native/file';


@Injectable({
  providedIn: 'root'
})
export class DownloadService {

  fileTransfer: FileTransferObject;

  constructor(private transfer: FileTransfer, private file: File) {
    this.fileTransfer = this.transfer.create();
  }

  download(url: string, destFileName: string) {
    this.fileTransfer.download(url, this.file.dataDirectory + destFileName).then((entry) => {
      console.log('download complete: ' + entry.toURL());
    }, (error) => {
      console.log('download failed' + error);
    });
  }
}

However, this results in compilation error:

ERROR in src/app/services/download.service.ts(20,47): error TS2339: Property 'dataDirectory' does not exist on type 'File'.

I've seen a similar question. However, I'm importing correctly as suggested by the accepted answer, so I believe this question is different.

like image 250
Chris Snow Avatar asked Dec 17 '22 18:12

Chris Snow


1 Answers

Try this :

import { File } from '@ionic-native/file/ngx';

When using Ionic4, you have to add /ngx to every @ionic-native imports. Basically, it provides an Ionic4 dedicated typing.

like image 126
Augustin R Avatar answered May 05 '23 17:05

Augustin R