2

不知道出了什么问题,但是当我尝试使用来自@ionic-native 的文件时,我收到错误“类型'typeof File' 上不存在属性'moveFile'”。在评论中询问后添加了包子

import { NavController } from 'ionic-angular';
import { ToastController } from 'ionic-angular';
import { File } from '@ionic-native/file';
import { Diagnostic } from '@ionic-native/Diagnostic';
import { CameraPreview } from 'ionic-native'
import { CameraPreviewOptions, CameraPreviewDimensions } from '@ionic-native/camera-preview';
declare var cordova: any; 

constructor(public navCtrl: NavController, public toastCtrl: ToastController) {
  //  this.checkPermissions();
  }
  fileName = fileName.split("/").pop();
    File.moveFile(currentPath, fileName, externalStoragePath, fileName).then(_ => {
    this.toastCtrl.create(

package.json根据评论的要求

{
  "name": "ionic-hello-world",
  "version": "0.0.0",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "4.0.2",
    "@angular/compiler": "4.0.2",
    "@angular/compiler-cli": "4.0.2",
    "@angular/core": "4.0.2",
    "@angular/forms": "4.0.2",
    "@angular/http": "4.0.2",
    "@angular/platform-browser": "4.0.2",
    "@angular/platform-browser-dynamic": "4.0.2",
    "@ionic-native/camera": "^3.6.0",
    "@ionic-native/camera-preview": "^3.6.0",
    "@ionic-native/core": "^3.6.1",
    "@ionic-native/diagnostic": "^3.6.1",
    "@ionic-native/file": "^3.6.1",
    "@ionic-native/splash-screen": "3.4.2",
    "@ionic-native/status-bar": "3.4.2",
    "@ionic/storage": "2.0.1",
    "ionic-angular": "3.1.1",
    "ionicons": "3.0.0",
    "rxjs": "5.1.1",
    "sw-toolbox": "3.4.0",
    "zone.js": "^0.8.5"
  },
  "devDependencies": {
    "@ionic/app-scripts": "1.3.6",
    "typescript": "~2.2.1"
  },
  "cordovaPlugins": [
    "cordova-plugin-whitelist",
    "cordova-plugin-statusbar",
    "cordova-plugin-console",
    "cordova-plugin-device",
    "cordova-plugin-splashscreen",
    "ionic-plugin-keyboard"
  ],
  "cordovaPlatforms": [
    "ios",
   {
      "platform": "ios",
      "version": "",
      "locator": "ios"
    }
   ],    
  "description": "camera-app: An Ionic project"
}
4

1 回答 1

3

您正在使用ionic-native 3.x.

您需要注入File构造函数并使用该对象。类中的静态函数存在于ionic-native 2.x.

constructor(public navCtrl: NavController, public toastCtrl: ToastController,
     public file:File) {
  //  this.checkPermissions();
  }
  fileName = fileName.split("/").pop();
    this.file.moveFile(currentPath, fileName, externalStoragePath, fileName).then(_ => {
    this.toastCtrl.create(

您还需要在app.module.tsFile中设置为提供者。

@NgModule({
 //..
 providers: [..,File,..]
  })
于 2017-05-02T05:29:52.107 回答