Reputation: 12729
i am trying to use $ionicPopup in my service .Actually when I am using in controller it run correctly .please click on button and check here is plunker http://plnkr.co/edit/wIss45ijr0DfvUVB1GPG?p=preview
But when I used in factory it gives error .Please check error in console.
Error:Maximum call stack size exceeded
http://plnkr.co/edit/l3rvPB7AZV1WIRbMEnXd?p=preview
ap.factory('utlity', ['$ionicPopup',function($ionicPopup) {
function showOtcresult(message){
var alertPopup = $ionicPopup.alert({
title: 'Alert',
template: message.toString()
});
alertPopup.then(function(res) {
console.log('Thank you for not eating my delicious ice cream cone');
});
}
return {
showOtcAlert:function showOtcresult(message){
showOtcresult(message)
}
}
}]);
Upvotes: 0
Views: 52
Reputation: 8465
The problem here is down to same name for two functions which caused loop call
showOtcresult
return {
showOtcAlert: function whateverNameForDebug(message) {
showOtcresult(message)
}
}
Upvotes: 0
Reputation: 17064
There's no need for the name in the function declaration, since it will be executed by calling the property key showOtcAlert
, so you need to do:
return {
showOtcAlert:function (message){
showOtcresult(message)
}
}
Upvotes: 3