Passing data from a page to another - Ionic1

Hello,
I’m new to Ionic, and I’m struggling with something simple.
I’ve used the Ionic tab template. I’ve a list of “conversations”, when you click on it, you’ll arrive on a “Detail Page”, and when you click on a button on this page, you’ll arrive on a “Second Detail Page”.
My problem is that I want my “Second Detail Page” to receive the data from the first “Detail Page” (name, lastText… defined in service.js)…
But, I don’t succeed in doing that!

Here is what I’ve tried…

APP JS
.state(‘tab.chat-detail’, {
url: ‘/chats/:chatId’,
views: {
‘tab-chats’: {
templateUrl: ‘templates/chat-detail.html’,
controller: ‘ChatDetailCtrl’,
}
}
})

.state('tab.chat-db_connect', {
    url: '/chats/:chatId',
    views: {
      'tab-chats': {
    templateUrl: 'templates/chat-db_connect.html',
    controller: 'DB_connect',
  }

CONTROLLER JS
.controller(‘ChatDetailCtrl’, function($scope, $state, $window, $stateParams, Chats, $ionicPopup, $http) {
$scope.chat = Chats.get($stateParams.chatId);

$scope.db_connect = function() {
$state.go(‘chat-db_connect’);
};

. .controller(“DB_connect”, ["$scope", “Auth”,’$state’,
function($scope, Auth, $state, $stateParams, Chats) {
$scope.chat = Chats.get($stateParams.chatId);
}])

try using services of angularjs

@baviskarmitesh is right, Try using a service/factory for passing data from one controller/page to another…

Thanks for your advice!

I’ve used this, but it only passes the data from the Chats Page to the first Detail Page (Chat-detail), and not the Second Detail Page (Db-connect)…:

.factory(‘Chats’, function() {
// Might use a resource here that returns a JSON array

var chats = [{
id: 0,
name: ‘Le XXX’,
lastText: ‘Bar à Cocktails’,
description: ‘Un bar à coktail semi-planqué qui saura surprendre vos papilles. Les créations maisons vous feront voyager…’,
preview: ‘img/xx22.jpg’,
face: ‘img/xx.jpg’,
city: ‘Paris’,
district: ‘Montorgueil’,
street: ‘Rue Tiquetonne’,
number: ‘13’,
zip: ‘75002’,
lat: 51.090209,
lng: 6.585863,
dates: ‘Mardi-Samedi: 18h-02h’,
website: ‘https://www.xx.paris/’,
}, {
id: 1,
name: ‘YY’,
lastText: ‘Micro-Clubbing’,
description: ‘Un bar à coktail semi-planqué qui saura surprendre vos papilles. Les créations maisons vous feront voyager…’,
preview: ‘img/yy.jpg’,
face: ‘img/yy.jpg’,
city: ‘Paris’,
district: ‘Pigalle’,
street: ‘Rue Frochot’,
number: ‘14’,
zip: ‘75018’,
lat: 51.090209,
lng: 6.585863,
dates: ‘Mardi-Samedi: 18h-02h’,
website: ‘https://www.yy.paris/’,
}];

return {
all: function() {
return chats;
},
remove: function(chat) {
chats.splice(chats.indexOf(chat), 1);
},
get: function(chatId) {
for (var i = 0; i < chats.length; i++) {
if (chats[i].id === parseInt(chatId)) {
return chats[i];
}
}
return null;
}
};
})

Any help? I’m still blocked on this point. I can’t pass my data through my third controller…