title: Angularjs Passing array between controllers
body: <p>I have been through several tutorials and posts about this topic and still can't seem to figure out what is wrong with my code. To me it seems I am having scoping issues with the data within my service. My code is split up into separate files. Here is my code:
  github link : <a href="https://github.com/StudentJoeyJMStudios/PetPinterest.git" rel="nofollow">https://github.com/StudentJoeyJMStudios/PetPinterest.git</a></p>
  
  <pre><code> //in dataService.js
   var app = angular.module('se165PetPinterestWebApp');
  
   app.service('SharedData', function ()
   {
      var categoryOfSelectedAnimals = [];
  
      this.setCatOfSelAnimals = function(pulledCategoriesFromParse)
      {
  
          categoryOfSelectedAnimals = pulledCategoriesFromParse;
          console.log('after assignment in set::' + categoryOfSelectedAnimals);
      };
      this.getCatOfSelAnimals = function()
      {
          console.log('in get::::' + categoryOfSelectedAnimals);
  
          return categoryOfSelectedAnimals;
      };
   });
  </code></pre>
  
  <p>in my first controller to set the data in signup.js</p>
  
  <pre><code>app.controller('SignupCtrl',['$scope', 'SharedData', function ($scope, SharedData)
  {  
       var Categories = Parse.Object.extend('Categories');
    var query = new Parse.Query(Categories);
  
    query.find({
        success: function(results)
        {
  
            $scope.availableCategoriesOfAnimals = results;
  
            SharedData.setCatOfSelAnimals(results);
  
  
        },
        error: function(error)
        {
            alert('Error: ' + error.code + ' ' + error.message);
        }
    });
    };
  }]);
  </code></pre>
  
  <p>Then in my other controller trying to get the data from the array within my service:</p>
  
  <pre><code>var app = angular.module('se165PetPinterestWebApp');
  app.controller('CatSelCtrl', function ($scope, SharedData)
  {
        $scope.availableCategoriesOfAnimals = SharedData.getCatOfSelAnimals();
  });
  </code></pre>
  
  <p>When I print the contents from the SharedData.getCatOfSelAnimals I get 0 every time. Please help. Thank you very much in advance.</p>
  
  <p>EDIT: After playing around with a string a bit I am finding the changed string in the set function is not saved into the service and when I call my get function within my service the string is not changed from the set method. Please help, thank you in advance.</p>
  
  <p>EDIT: So it looks like when I navigate to new page by using window.location.href = '../views/categorySelection.html'; in my signup.js it reloads my dataService.js which re-sets my variables back to nothing. Does anyone have any ideas as to how to fix this?</p>