Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Pascal Jeske
Pascal Jeske
7,877 Points

Post Content to $scope doesn't work when trying to change $location.path

Hi guys, I'm having a hard time bringing my response data to the $scope once I change the $location of my angular app.

The current state is, im recieving the user data on login from my express middleware and now I want to relocate to the profile page and update a $scope var to fill my ng-repeat directive. The response data is logged as desired but on location change it seems like the scope is reset.

My Code looks like this:

Controller Login Function:

$scope.login = function($event){
        $event.stopPropagation();
        eventDataService.getEvents($scope.email,$scope.password,function(response){
            console.log(response.data)
            $scope.events = response.data.events
        })
          $location.path('/profile');
  }

eventDataService:

app.service('eventDataService', function($http){
    this.getEvents = function(email,password,callback){
        $http({
          method: 'POST',
          url: '/login',
          data: {
              email: email,
              password: password
          }
      })
      .then(callback)
    }
})

I don't know how to solve this issue.