I'm trying to return a promise with actionsheet (ionic).
Error:
TypeError: Cannot read property 'then' of undefined at CambiarImagenesController.seleccionarImagen (cambiarimagenes.controller.js:33)
This is the function that has the problem (controller):
function seleccionarImagen() {
cambiarImagenesService.seleccionarImagen() //line 33
.then(reemplazarImagen);
I think the problem is that the function "seleccionarImagen" is not returning correctly the promise.
So this is the function "seleccionarImagen"
function seleccionarImagen(){
console.log("paso 1");
// Show the action sheet
$ionicActionSheet.show({
buttons: [
{ text: 'Cámara' },
{ text: 'Galería' }
],
cancelText: 'Cancelar',
cancel: function() {
// add cancel code..
},
buttonClicked: function(index) {
if(index == 0){
var promise = obtenerImagen(Camera.PictureSourceType.CAMERA)
.then(function(val){
// asignamos el valor asincrónico
urlImagen = val;
// retornamos el valor a la cadena
return val;
});
// retornamos la promesa de manera síncrona
return promise;
}
else if(index == 1){
var promise = obtenerImagen(Camera.PictureSourceType.PHOTOLIBRARY)
.then(function(val){
// asignamos el valor asincrónico
urlImagen = val;
// retornamos el valor a la cadena
return val;
});
// retornamos la promesa de manera síncrona
return promise;
}
}
})
}
The are a few methods like "obtenerImagen" thats return the promise perfect. I know that because I made a poup and returned me the promise right, but now I need an actionsheet.
Thanks for help!