当用户单击Ionic ActionSheet
中的按钮时,我正在尝试在我的 ionic 应用程序中打开文件资源管理器。这可以通过将<input type="file">
放入 HTML 模板中简单地完成。但我在行动表中给出了两个选项
- 打开相机
- 打开文件资源管理器我使用
$cordovaCamera
插件打开相机,但我不知道如何打开文件探索。这是我的代码供参考
$ionicActionSheet.show({
buttons: [{ text: 'Open File Explorer //or <input type="file">' },
{ text: 'Open Camera' }],
buttonClicked: function(buttons) {
if(buttons == 0)
{
// what to do here ?
return true;
}
if(buttons == 1)
{
$scope.takeImage(Camera.PictureSourceType.CAMERA);
return true;
}}
})
我通过插入<input type="file" id="fileupload" style="display:none">
来实现这一点,在我的控制器中我使用
if(buttons == 0)
{
// what to do here ?
document.getElementById('fileupload').click()
...
}
我希望这可能会对某人有所帮助。
使用cordova-plugin-file
插件处理文件管理器
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/
使用 安装插件
cordova plugin add cordova-plugin-file
然后使用"deviceready
事件"下提供的函数。
More info : https://github.com/apache/cordova-plugin-file