Using $scope in Ionic popup

Hi guys,

I followed documentation to set a popup in my project.
This works well.

But when I call the confirmPopup() function, I’m not in controller (I’m in services.js), so when I define scope: $scope, I have an obvious $scope is unknown error.

How do you solve this? Thanks a lot !

Find bellow the full code if you need it.

controllers.js

$scope.confirm_redeem_reward = function(asked_reward) {
      RewardModel.displayConfirmRedeemReward(asked_reward)
    };

services.js

  RewardModel.displayConfirmRedeemReward = function(asked_reward) {
     var confirmPopup = $ionicPopup.confirm({
       title: 'Confirmation',
       templateUrl: 'templates/popups/confirm_redeem_reward.html',
       scope: $scope,
       buttons: [{
          text: 'Cncel',
          type: 'button-default'
        }, {
          text: 'OK',
          type: 'button-positive',
          onTap: function(e) {
            RewardModel.useReward(asked_reward.id);
            RewardModel.used_reward_or_deal_name = asked_reward.name;
          }
        }]

     });
     confirmPopup.then(function(res) {
       // Nothing
     });
    };

confirm_redeem_reward.html

Do you want to redeem the reward :<br/>
{{asked_reward.name}} ?

I don’t know why you need the $scope there, and if this is the better solucion, but, maybe you can inject $rootScope into your service, and on confirmPopup, send an event, that is listen in you $scope.

Do you understand what I mean?

Humm not sure to understand (note that I’m begginer to JS world ^^).
But I have the feeling that what I’m trying to do is really standard and there is no need to find a trick.

The only difference of my code compared to the documentation is that, everything is not hardcoded in the controller (bad !).

Seems like you would need to do this at some point:
$scope.asked_reward = asked_reward;

try:

scope: this,

instead of

scope:$scope,

Try: rootScope: this, // It works for me :)…