如何使用离子和角度在模态内显示选定的图像名称
how to show selected image names inside modal using ionic and angular?
>我使用了一个cordova插件从ios库中选择图像并显示图像。我在这里面临的问题是,我想要一个应该显示所选图像名称的模态,但我无法显示此模态。这是我的代码:
我的控制器:
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();
};
});
我已经截断了图像的名称,并在截断的imgname中截断了扩展名。我希望当用户在选择图像后单击完成按钮并在该模态内显示他们的名字时显示我的模态。
您必须在
成功函数中调用$scope.openModal()
。事实上,results
仅在此函数中可用,并且异步可用(在用户选择后),因为$cordovaImagePicker.getPictures(options)
返回一个 promise。
$cordovaImagePicker.getPictures(options)
.then(function (results) {
// on success
...
openModal();
}, function(error) {
// on error
...
});
在你发布的代码中,你已经将函数定义为$scope.openModal
但是在调用函数时,你只放置了openModal()
,它不会找到附加到$scope变量的函数。
您应该调用该函数,$scope.openModal();
相关文章:
- 使用JSP从服务器检索和显示图像
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 使用FormData上传AJAX图像;t在服务器端显示图像
- 选择文件后显示图像
- Chrome(webkit?)无法在幻灯片中正确显示图像
- 如何使用javascript显示图像
- 使用JS按顺序显示图像,而不是随机显示
- 使用服务器上的HTML/js在网页上显示图像
- 我想在选择输入文件上显示图像
- Javascript:单击单选按钮时显示图像
- 如何将JSON结果设置为'src'共'img'以在ASP.NET MVC4中显示图像
- 无法在cakepp布局中显示图像
- 页面加载后通过javascript显示图像
- 将图像文件存储在猫鼬模式中的二进制数据中,并以html形式显示图像
- 使用AngularJs数据绑定的三元运算符显示图像
- 加载时画布上未显示图像
- 运行POST时显示图像
- NodeJS上没有显示图像
- 从Javascript在表中显示图像
- 如何在MVC5中运行时在HTML5 Canvas中显示图像