Typescript Error: Cannot find name 'cordova'

Viewed 11920

import {Component} from '@angular/core';
import {NavController, Platform, AlertController} from 'ionic-angular';
import {Transfer, TransferObject} from '@ionic-native/transfer';
import {File} from '@ionic-native/file';



@Component({
  selector: 'page-about',
  templateUrl: 'about.html',
  providers: [Transfer, TransferObject, File]
})
export class AboutPage {

  storageDirectory: string = '';

  constructor(public navCtrl: NavController, public platform: Platform, private transfer: Transfer, private file: File, public alertCtrl: AlertController) {
    this.platform.ready().then(() => {
      // make sure this is on a device, not an emulation (e.g. chrome tools device mode)
      if(!this.platform.is('cordova')) {
        return false;
      }

      if (this.platform.is('ios')) {
        this.storageDirectory = cordova.file.documentsDirectory;
      }
      else if(this.platform.is('android')) {
        this.storageDirectory = cordova.file.externalDataDirectory;
  console.log(this.storageDirectory);
      }
      else {
        // exit otherwise, but you could add further types here e.g. Windows
        return false;
      }
    });
  }
  
   downloadImage() {

    this.platform.ready().then(() => {

      const fileTransfer: TransferObject = this.transfer.create();

      const imageLocation = 'http://html5demos.com/assets/dizzy.mp4';

      fileTransfer.download(imageLocation, this.storageDirectory + 'dizzy.mp4').then((entry) => {
       
    const alertSuccess = this.alertCtrl.create({
          title: `Download Succeeded!`,
          subTitle: `successfully downloaded to: ${entry.toURL()}`,
          buttons: ['Ok']
        });

        alertSuccess.present();

      }, (error) => {

        const alertFailure = this.alertCtrl.create({
          title: `Download Failed!`,
          subTitle: `was not downloaded. Error code: ${error}`,
          buttons: ['Ok']
        });

        alertFailure.present();

      });

    });

  }


}

I am getting the error attached in screenshot.I am getting error while running my project build in ionic 2, though i have installed 'typings' with below command

npm install -g typings typings, install dt~cordova --save --global

and tried every possible method to remove this error, checked all cordova plugin like File, file transfer but still error is not resolving.

Can anyone look for it.

Here attached also the code, i dont have any idea where i am going wrong..

2 Answers
Related