I want to use the “cordova-plugin-filetransfer”.
I added this plugin to my ionic 2 app:
ionic plugin add cordova-plugin-file-transfer --save
And also I have imported the correpondings typings:
typings install dt~cordova --save --global
typings install dt~cordova/plugins/filesystem --save --global
typings install dt~cordova/plugins/filetransfer --save --global
But when I try to use “cordova” or “FileTransfer” the Angular 2 compiler (ngc) gives me errors:
Cannot find name 'cordova'
Cannot find name 'FileTransfer'
This error can be replicated using the “blank” template from ionic 2:
ionic start Demo blank --v2 ionic plugin add cordova-plugin-file-transfer --save ionic plugin platform add android
Modifying the “home.ts”
import { Component } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public platform: Platform, public navCtrl: NavController) {
let path: string = "";
if (this.platform.is("android")) path = cordova.file.externalDataDirectory;
else if (this.platform.is("ios")) path = cordova.file.documentsDirectory;
else if (this.platform.is("windows")) path = cordova.file.dataDirectory;
const fileTransfer = new FileTransfer();
}
}
ionic build android
The output is something like:
[12:19:37] ngc started ...
[12:19:38] copy finished in 216 ms
[12:19:38] lint started ...
[12:19:40] tslint: C:/Datos/Proyectos/Pruebas/Demo/src/pages/home/home.ts, line: 16
Unused variable: 'fileTransfer'
L16: const fileTransfer = new FileTransfer();
[12:19:40] lint finished in 2.52 s
[12:19:53] Error: Error at C:/Datos/Proyectos/Pruebas/Demo/.tmp/pages/home/home.ts:12:49
[12:19:53] Cannot find name 'cordova'.
[12:19:53] Error at C:/Datos/Proyectos/Pruebas/Demo/.tmp/pages/home/home.ts:13:50
[12:19:53] Cannot find name 'cordova'.
[12:19:53] Error at C:/Datos/Proyectos/Pruebas/Demo/.tmp/pages/home/home.ts:14:54
[12:19:53] Cannot find name 'cordova'.
[12:19:53] Error at C:/Datos/Proyectos/Pruebas/Demo/.tmp/pages/home/home.ts:16:34
[12:19:53] Cannot find name 'FileTransfer'.
[12:19:53] ngc failed
[12:19:53] ionic-app-script task: "build"
[12:19:53] Error: Error
Any idea how to use those typings? Do I have to configure something?