gpt4 book ai didi

javascript - 如何使用 ionic 和 Angular 在模态内显示选定的图像名称?

转载 作者:行者123 更新时间:2023-11-29 21:36:04 25 4
gpt4 key购买 nike

我使用了一个 cordova 插件从 ios 画廊中选择图像并显示图像。我在这里面临的问题是我想要一个应该显示所选图像名称的模态,但我无法显示此模态。这是我的代码:

我的 Controller :

app.controller('ImagePickerController', function($scope, $rootScope,$cordovaImagePicker, $ionicPlatform, $cordovaContacts,$ionicModal) {
$scope.ready = false;
$scope.images = [];

$scope.openGallery = function() {
alert("hii");

var options = {
maximumImagesCount: 20, // Max number of selected images, I'm using only one for this example
width: 800,
height: 800,
quality: 100 // Higher is better
};

$cordovaImagePicker.getPictures(options).then(function(results) {
for(var i=0 ; i<results.length ; i++){
//alert(results[i]);
//console.log('img', imageUri);
$scope.images.push(results[i]);
var imagename = results[i];
$scope.truncatedimgname = imagename.replace(/^.*[\\\/]/, '')
alert(truncatedimgname);
}

}, function(err) {
// error
});

openModal();
};

$scope.openModal = function(animation) {
alert("modal");
$ionicModal.fromTemplateUrl('contact-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
$scope.modal.show();
});
};
$scope.closeModal = function() {
$scope.modal.hide();
};

});

我在 truncatedimgname 中 chop 了带有扩展名的图像名称。我希望当用户在选择图像并在该模态中显示其名称后单击完成按钮时显示我的模态。

最佳答案

您必须在成功函数中调用 $scope.openModal()。事实上,results 仅在此函数内可用,并且异步(在用户选择之后),因为$cordovaImagePicker.getPictures(options) 返回 promise .

$cordovaImagePicker.getPictures(options)
.then(function (results) {
// on success
...

openModal();
}, function(error) {
// on error
...
});

关于javascript - 如何使用 ionic 和 Angular 在模态内显示选定的图像名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34852400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com