我正在尝试使用 FileTransfer Ionic 4 示例。
我已经执行了安装步骤:
ionic cordova plugin add cordova-plugin-file
npm install @ionic-native/file
Run Code Online (Sandbox Code Playgroud)
我创建了一个服务:
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);
});
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这会导致编译错误:
src/app/services/download.service.ts(20,47) 中的错误:错误 TS2339:“文件”类型上不存在属性“dataDirectory”。
我看过一个类似的问题。但是,我按照接受的答案的建议正确导入,所以我相信这个问题是不同的。
Aug*_*n R 10
尝试这个 :
import { File } from '@ionic-native/file/ngx';
Run Code Online (Sandbox Code Playgroud)
使用 Ionic4 时,您必须添加/ngx到每个@ionic-native导入中。基本上,它提供了一个 Ionic4 专用类型。
| 归档时间: |
|
| 查看次数: |
1816 次 |
| 最近记录: |