Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading data from service using $routeParam

I am trying to load a group of messages depending on an ID that is part of the app's route. The routeParams object appears to be a promise, and I'm not sure how to set it up so that it waits until the routeParams object have loaded to load the group of messages:

var current = Messages.rest({m_gid:$routeParams.gid}).query({}, function () { 
    $scope.messages.current = Messages.messages.current = current.data;
}); 

I'm sure that this is simple, I'm just at a loss...

like image 360
Wandering Digital Avatar asked Mar 14 '26 06:03

Wandering Digital


1 Answers

You can subscribe to the $routeChangeSuccess event.

$rootScope.$on('$routeChangeSuccess', function(event, current, previous){
    //do work with $routeParams here
});
like image 76
Jonathan Palumbo Avatar answered Mar 16 '26 20:03

Jonathan Palumbo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!