打字稿错误:找不到名字’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插件,如文件,文件传输但仍然错误无法解决.

        任何人都可以寻找它.

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

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

        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';
        
        declare let cordova: any;
        
        @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();
        
              });
        
            });
        
          }
        
        
        }
        相关文章
        相关标签/搜索
        4887铁算盘一句解特马香港马会开码结果直播 开奖结果-香港最快开奖现场直播-王中王资料 一肖中特-2018年管家婆彩图