title: Angular js , passing object from service
body: <pre><code>'use strict';
  
  var app = angular.module('app');
  app.factory('currTripService', function() {
        var currtrip ='';
  
      return{
          setCurrTrip: function(trip){ 
              currtrip = trip ;
          },
          getCurrTrip: function(){ 
              return currtrip ;
          },
      }
  }); 
  
  
  app.controller('TripCreateController', function($scope, $location, Trip,currTripService) {
      //The save method which is called when the user wants to submit their data
      $scope.save = function() {
  
          //Create the forum object to send to the back-end
          var trip = new Trip($scope.trip);
            console.log(trip);
           currTripService.setCurrTrip(trip);
           console.log(currTripService.getCurrTrip());
          //Save the forum object
          trip.$save(function() {
              //Redirect us back to the main page
              $location.path('/trip/day/1');
  
          }, function(response) {
  
              //Post response objects to the view
              $scope.errors = response.data.errors;
          });
      }
  });
  
  app.controller('TripDayCreateController',function($scope,$routeParams,currTripService){
      $scope.items=[];
      $scope.trip = currTripService.getCurrTrip();
   console.log($scope.trip.city);
  
      // $scope.products = productService.getProducts();
      $scope.addItem = function(item) {
                  $scope.items.push(item);
                  $scope.item = {};
      }
  });
  </code></pre>
  
  <p>When i click on /trip/new , its does the save in TripCreateController and set the trip object inside currTripService. 
  Then when redirected to TripDayCreateContoller the <strong>console.log(currTripService.getTrip())</strong> , returns 'undefined' </p>
  
  <p>Is it because Trip is an object ? How can i fix this ?</p>