微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

打字稿错误:找不到名字’cordova’

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.我在离子2中运行我的项目构建时遇到错误,虽然我已经使用下面的命令安装了’typings’

npm install -g typings typings,安装dt~cordova –save –global

并尝试了每种可能的方法删除错误,检查所有cordova插件,如文件,文件传输但仍然错误无法解决.

任何人都可以寻找它.

这里附有代码,我也不知道我哪里出错了..

@H_502_18@解决方法
我编辑了你的代码,添加了declare let cordova:any;这暴露了cordova api以供使用.希望这有帮助.

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

declare let cordova: any;

@Component({
  selector: 'page-about',buttons: ['Ok']
        });

        alertFailure.present();

      });

    });

  }


}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐