函数未在 window.plugins in Angular/Ionic 中运行
function not running in window.plugins in Angular/Ionic
问题:我正在尝试以base 64格式存储图片,但window.plugins.Base64.encodeFile方法未运行。
我已经在本地安装了科尔多瓦插件,$cordovaImagePicker工作正常。 从手机获取图像后,它仅将本地图像路径存储在 $scope.collected.selectedImage 中,而不是将其转换为 base 64 格式。
感谢您的帮助!!
'use strict';
angular.module('copula')
.controller('ItemsCtrl', function($scope, $state, Auth, Item, $firebaseObject, $cordovaImagePicker, $ionicPlatform) {
var ref = new Firebase('https://copula.firebaseio.com/users');
var authData = Auth.$getAuth();
var itemsObject = $firebaseObject(ref.child(authData.uid + '/items'));
itemsObject.$loaded().then(function() {
$scope.items = itemsObject;
});
$scope.collection = {
selectedImage: ''
};
$scope.item = {};
$ionicPlatform.ready(function() {
$scope.getImageSaveContact = function() {
// Image picker will load images according to these settings
var options = {
maximumImagesCount: 1, // Max number of selected images, I'm using only one for this example
width: 800,
height: 800,
quality: 80 // Higher is better
};
$cordovaImagePicker.getPictures(options).then(function (results) {
$scope.collection.selectedImage = results[0]; // We loading only one image so we can use it like this
window.plugins.Base64.encodeFile($scope.collection.selectedImage, function(base64){ // Encode URI to Base64 needed for contacts plugin
console.log("before encoding");
$scope.collection.selectedImage = base64;
console.log(base64);
});
console.log($scope.collection.selectedImage);
}, function(error) {
console.log('Error: ' + JSON.stringify(error)); // In case of error
});
};
});
$scope.$on('$ionicView.beforeEnter', function (event, viewData) {
viewData.enableBack = true;
});
$scope.submitItem = function() {
ref.child(authData.uid).child('items').push(Item.pushAttrs($scope.item));
$scope.item = {};
$state.go('main.home');
};
});
在关于此插件的所有教程中,他们将结果(base64)用于ng-src,如下所示:
<img ng-src="{{collection.selectedImage}}">
这意味着这个插件正在返回一个路径,这是这个插件的正常行为。
console.log('file base64 encoding: ' + base64);
它返回转换后的base64 img的路径。
您的结果[0] 路径和 base64 路径应该不同。
来源 : http://www.gajotres.net/accessing-image-galery-using-ionic-and-ngcordova/2/
资料来源:https://forum.ionicframework.com/t/how-to-load-image-from-android-local-storage/25132/3
相关文章:
- 如何使用phaser使html5游戏在移动设备浏览器上运行
- 使用压缩的JavaScript文件(不是运行时压缩)
- Javascript运行php文件,然后下载文件
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 我已经创建了一个jquery转盘,并使用if条件来运行和停止转盘
- Angularjs代码未在匿名函数中运行
- jquery设置为使用参数运行
- 如何根据时间运行不同的脚本
- 在子控制器中触发时,Ionic AngularJS父动画未正确运行
- Cordova(Ionic):Splashscreen只在Android上运行一次
- 无法在Ionic服务中运行角度spotify方法
- 函数未在 window.plugins in Angular/Ionic 中运行
- Ionic:应用程序启动时角度控制器未运行
- 深层中的Ionic/Codova-cli命令-构建、编译、运行、准备
- Ionic Angular不能在Android设备上运行
- Ionic 2:检查是否在浏览器环境中运行的最佳方法
- Ionic App在移动浏览器中运行流畅
- ionic应用程序中的计时器(setInterval)在后台运行一段时间后进入睡眠状态
- WebRTC视频通话和IONIC,调用时,应用程序在后台运行
- Ionic运行android不工作