External Json File : Detail Page

Hi everyone,

I use the Tab Template, with list of chats and chats detail. I’ve put the data into a json file, and add it like this in my code : $http.get(“http://abcd/Chats.json”).
The data are showing on the List of Chats, but it doesn’t work on the Detail Page.
I’ve tested a lot of solution, but I’m still getting an error…

Here is my code:

  SERVICE
 angular.module('starter.services', [])

.factory('Chats', function($http) {
 // Might use a resource here that returns a JSON array

return {
getChats: function() {
  return $http.get("http://abcd/Chats.json").success(function(response){
    chats=response;
    return chats;
  });
},

get: function(chatId) {
  for (var i = 0; i < chats.length; i++) {
    if (chats[i].id === parseInt(chatId)) {
      return chats[i];
    }
  }
  return null;
}
};

});

CONTROLLER

     .controller('ChatsCtrl', function($scope, Chats) {
     Chats.getChats().success(function(response){
     $scope.chats =response;
      });
      })

  .controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {
  $scope.chat = Chats.get($stateParams.chatId);
  })

My error is: cannot read property of chat undefined…
Any help please?