属性 'dataDirectory' 在类型 'File' 上不存在
Property 'dataDirectory' does not exist on type 'File'
我正在尝试使用 FileTransfer Ionic 4 example。
我已经执行了安装步骤:
ionic cordova plugin add cordova-plugin-file
npm install @ionic-native/file
我创建了一个服务:
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);
});
}
}
然而,这会导致编译错误:
ERROR in src/app/services/download.service.ts(20,47): error TS2339: Property 'dataDirectory' does not exist on type 'File'.
我看过 。但是,我按照接受的答案的建议正确导入,所以我相信这个问题是不同的。
试试这个:
import { File } from '@ionic-native/file/ngx';
使用 Ionic4 时,必须将 /ngx
添加到每个 @ionic-native
导入。基本上,它提供了一个 Ionic4 专用类型。
我正在尝试使用 FileTransfer Ionic 4 example。
我已经执行了安装步骤:
ionic cordova plugin add cordova-plugin-file
npm install @ionic-native/file
我创建了一个服务:
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);
});
}
}
然而,这会导致编译错误:
ERROR in src/app/services/download.service.ts(20,47): error TS2339: Property 'dataDirectory' does not exist on type 'File'.
我看过
试试这个:
import { File } from '@ionic-native/file/ngx';
使用 Ionic4 时,必须将 /ngx
添加到每个 @ionic-native
导入。基本上,它提供了一个 Ionic4 专用类型。