Since you're new to angularjs, a simpler approach would be to use $ rootScope to exchange data between your controllers (and the views associated with them). A.
Here is an example:
angular.module('MyApp', []) .config(['$routeProvider', function ($routeProvider) { $routeProvider .when('/', { templateUrl: '/views/main.html', controller: 'MainCtrl' }) .when('/first-page', { templateUrl: '/views/first.html', controller: 'FirstCtrl' }) .when('/second-page', { templateUrl: '/views/second.html', controller: 'SecondCtrl' }); }]) .controller('MainCtrl', ['$rootScope', function ($rootScope) { // Will be available everywhere in your app $rootScope.users = [ { name: 'Foo' }, { name: 'Bar' } ]; }]) .controller('FirstCtrl', ['$rootScope', '$scope' function ($rootScope, $scope) { // Only available inside first.html $scope.bazUser = { name: 'Baz' }; // Add to global $rootScope.users.push($scope.bazUser); }]) .controller('SecondCtrl', ['$rootScope', '$scope' function ($rootScope, $scope) { console.log($rootScope.users); // [{ name: 'Foo' }, { name: 'Bar' }, { name: 'Baz' }]; }]);
inside second.html for example
<ul> <li ng-repeat="user in users">{{user.name}}</li> </ul>
SergeL
source share