user944513
user944513

Reputation: 12729

why alert is not display while using service?

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

Answers (2)

maurycy
maurycy

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

Omri Aharon
Omri Aharon

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)
      }
  }

Plunker

Upvotes: 3

Related Questions