我正在尝试使用以下Ionic插件,以便可以打开图库并选择多个图像:https://ionicframework.com/docs/native/image-picker#installation
我面临的问题是,当我点击按钮查看“我的照片”时,我什么都没得到。
为了安装,我首先运行以下命令,这是文档中插件的安装的一部分:
ionic cordova plugin add cordova-plugin-telerik-imagepicker
npm install @ionic-native/image-picker
这时,我有以下代码来运行图像选择器:
HTML
<button ion-button full round (tap)="openImagePicker()">My Photos</button>
TS
import { Camera, CameraOptions } from '@ionic-native/camera';
import { ImagePicker } from '@ionic-native/image-picker/ngx';
...
constructor(
...
private camera: Camera,
private imagePicker: ImagePicker,
) {
...
openImagePicker(){
let options= {
maximumImagesCount: 5,
}
var photos = [];
this.imagePicker.getPictures(options)
.then((results) => {
console.log(results);
}, (err) => { console.log(err) });
}
答案 0 :(得分:2)
您的代码没有问题。由于您的应用程序是Ionic V3,因此应使用以下命令来安装插件和节点模块。
ionic cordova plugin add cordova-plugin-telerik-imagepicker --variable PHOTO_LIBRARY_USAGE_DESCRIPTION="your usage message"
npm install --save @ionic-native/image-picker@4