title: how to push to a controller array from a factory? or execute a controller function from factory
body: <p>I am writing a chat application in cordova that receives push notifications. </p>
  
  <p>Upon receiving a message, I check if the user is currently on the chat page. If he is, I want to make a call to my server to update the array that displays messages. </p>
  
  <p>My push functions are in a factory and when a push comes in, it executes <code>onNotification</code></p>
  
  <p>My problem is that I can't access the <code>$scope.messages</code> array in my controller to push the new message. I've tried adding $scope to my factory but that didn't work.</p>
  
  <p>How do I access or push to an array that exists in my controller from a factory? </p>
  
  <p>Edit: Just realized an alternative. Is there a way for a factory to execute a function in the controller? I could also accomplish what I need if this was possible</p>
  
  <p>Note: <code>onNotification</code> is a plugin from cordova that is called when a notification is received. I can't pass anything into onNotification. </p>
  
  <p>Here's the essential/pseudo bits of code I currently have.</p>
  
  <p>Chat controller</p>
  
  <pre><code>.controller('ChatCtrl',function($scope, ...etc){
      $scope.messages = [];
  }
  </code></pre>
  
  <p>Factory</p>
  
  <pre><code>.factory('PushService'['$http',function($http){
  
     onNotification: function(e){
  
           $http.get('my_server_url')
           .success(function(data){
                // HERE I want to add the new data to $scope.messages from my controller, 
                // but I don't know how to access $scope.messages
                // Alternatively, if it's possible to execute a function in my controller 
               // from this factory that would work as well
           })
           .error(function(data){ //handle error});
  
     }
  }]);
  </code></pre>