I am loading a message list in an inbox , the most recent 5 messages in the list. I have trouble refreshing the page so that the page always shows the latest 5 messages in the list.
Message page just called the service the first time its opened. How do I recall the service ? For other services like user , I have been using $interval to update the $scope.data
Is it possible to recall service everytime it is opened?
Template
<div class="list">
  <ul ng-controller="MessagesCtrl">
    <li ng-repeat="message in messages.data" id="message{{message.id}}"  class="item">
        <a href="#" class="messageIcon">{{message.user}}</a>  
  <p>{{message.title}}</p><a ng-click="deleteItem($index)">x</a>
    </li>
</ul>
Service
angular
    .module('starter.controllers', [])
    .factory("Messages", function() {
        var Messages = {};
        return {
            getData: function($http) {
                return $http.get("http://website.com/index.php/id/user/get_message/i").
                success(function(response) {
                    /// console.log(JSON.stringify(response));
                    Messages.data = response.data;
                    return Messages;
                }).error(function(data, status, headers, config) {
                    // log error
                });
            }
        }
    });
Controller
angular
    .module('starter.controllers', [])
    .controller('MessagesCtrl', function($scope, Messages, $http) {
    Messages
        .getData($http)
        .then(function(data) {
            $scope.messages = data;
        });
});
 
     
    