One way to move things from your main controller is to exchange and make any changes to the data between the controllers inside the service or factory (described quite well in this article ).
Here is the updated script . You just need to inject the itemsService into any controller that you want to access the item data.
angular.module('test', []) .service('itemsService', function(){ var items = ['A', 'B', 'C', 'D']; return{ getItems: function(){ return items; }, changeItem: function(index, value){ items[index] = value; } } }) .controller('MainCtrl', function($scope, itemsService) { $scope.items = itemsService.getItems(); $scope.change = function(idx) { itemsService.changeItem(idx, 'X'); } })
source share