title: Access scope inside an angular js factory
body: <p>I'm using the ionic framework and need to be able to call a popup from muliple places in my code so I thought I would move it into a factory.  The popup uses an input field and I want to get the value of it.  Normally I would just call <code>$scope.parentGate.answer</code> but because it's in a factory I don't have access to the scope.  Any ideas how I can get the value of the input field?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>angular.module('starter.services', [])
  .factory('parentGate', function ($ionicPopup, Helpers) {
      return {
          Show: function(scope, SuccessCallback) {
              var first = Helpers.RandomNumber(1, 5) * 10;
              var second = Helpers.RandomNumber(11, 22);
              var title = 'What does ' + first + ' + ' + second + ' equal?'
              // An elaborate, custom popup
              return $ionicPopup.show({
                  template: '&lt;h4 class="text-center"&gt;' + title + '&lt;/h4&gt;&lt;div class="list"&gt;&lt;label class="item item-input"&gt;&lt;input type="number" ng-model="parentGate.answer" placeholder="Answer..."&gt;&lt;/label&gt;&lt;/div&gt;',
                  title: "Parent Gate",
                  //subTitle: title,
                  scope: scope,
                  buttons: [
                    { text: 'Cancel' },
                    {
                      text: 'Continue',
                      type: 'button-positive',
                      onTap: function(e) {
  
                        //
                        // I can't access $scope.parentGate.answer here.  
                        // How else can I do it?
                        //
                        if ($scope.parentGate.answer == first + second) { 
  
                          console.log("correct");
                          SuccessCallback();
                        } else {
                          console.log("wrong!");
                          e.preventDefault();
                        }
                      }
                    }
                  ]
              });
          }
      };
  });
  </code></pre>