Ionic3+Angular5/CLI7调用图库图片失败求助
Problem Description
I'm working on a project built with Ionic 3, Angular CLI 7, and Angular 5, and I'm unable to retrieve images from the photo gallery. When calling the getPicture method (either via @ionic-native/image-picker or @ionic-native/camera), I get this error:
Object(WEBPACK_IMPORTED_MODULE_1__ionic_native_core["cordova"]) is not a function. (In ‘Object(WEBPACK_IMPORTED_MODULE_1__ionic_native_core["cordova"])(this, "getPicture", { "callbackOrder": "reverse" }, arguments)’, ‘Object(WEBPACK_IMPORTED_MODULE_1__ionic_native_core["cordova"])’ is an instance of Object)
Code Snippets
ImagePicker Implementation:
let options = { maximumImagesCount: 1 }; this.imagePicker.getPictures(options).then((results) => { for (var i = 0; i < results.length; i++) { this.imgPreview = results[i]; this.base64.encodeFile(results[i]).then((base64File: string) => { this.regData.avatar = base64File; }, (err) => { }); } }, (err) => { console.log(err); });
Camera Implementation:
var sourceType = this.camera.PictureSourceType.PHOTOLIBRARY; var options = { quality: 100, sourceType: this.camera.PictureSourceType.PHOTOLIBRARY, saveToPhotoAlbum: false, correctOrientation: true }; this.camera.getPicture(options).then((imagePath) => { console.log("Img path: " + imagePath); if (this.platform.is('android') && sourceType === this.camera.PictureSourceType.PHOTOLIBRARY) { this.filePath.resolveNativePath(imagePath) .then(filePath => { let correctPath = filePath.substr(0, filePath.lastIndexOf('/') + 1); let currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.lastIndexOf('?')); }); } else { var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1); var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1); } }, (err) => { console.log(err); });
Steps Already Tried
- Upgraded all native plugins to version
5.0.0-beta.15— no improvement. - Downgraded
@ionic-native/image-pickerand@ionic-native/base64to match the version of@ionic-native/core— this seemed to fix the original "cordova is not a function" error, but now when running via Ionic DevApp, I get aplugin_not_installederror even though thetelerik-imagepickerplugin is already added to Cordova.
Note
I had to step away from the project temporarily and haven't had a chance to test the solution suggested by Sergey yet. I'm hoping to get more guidance to resolve this fully.
内容的提问来源于stack exchange,提问作者Mary

