方法
hola() {
return new Promise((resolve, reject) => {
if(true) {
resolve(true)
}
})
}
Run Code Online (Sandbox Code Playgroud)
调用方法
this.hola.then(data => console.log(data));
Run Code Online (Sandbox Code Playgroud)
错误
类型“() => Promise<{}>”上不存在属性“then”。
我已经尝试重新启动离子服务,但它不断抛出该错误
我已经安装了文件传输插件,因为它在这里提到
这是app.module.ts中的代码:
import { FileTransfer } from '@ionic-native/file-transfer';
providers: [
...
FileTransfer,
...
]
Run Code Online (Sandbox Code Playgroud)
这是错误
类型“ FileTransferOriginal”不可分配给“提供者”类型。类型'FileTransferOriginal'缺少类型'FactoryProvider'的以下属性:提供,useFactoryts(2322)(别名)const FileTransfer:FileTransferOriginal导入FileTransfer
我正在尝试使用以下方式将图像上传到服务器
"cordova-plugin-file-transfer": "^1.7.1",
"@ionic-native/file-transfer": "^5.0.0",
Run Code Online (Sandbox Code Playgroud)
component.ts
takePicture() {
const options: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
targetWidth: 500,
targetHeight: 500,
saveToPhotoAlbum: false
};
this.camera.getPicture(options)
.then((imageData) => this._img.uploadImage(imageData))
.catch(err => console.log(err));
}
Run Code Online (Sandbox Code Playgroud)
imageProvider.ts
import { FileTransfer, FileUploadOptions, FileTransferObject } from "@ionic-native/file-transfer/ngx";
...
uploadImage(img) {
const url = `${this.apiURL}/images/upload`;
// File for Upload
var targetPath = img;
var options: FileUploadOptions = {
fileKey: 'image',
chunkedMode: false,
mimeType: 'multipart/form-data'
};
const fileTransfer: FileTransferObject = this.transfer.create();
fileTransfer.upload(targetPath, …Run Code Online (Sandbox Code Playgroud)