How do you pass current $routeParams to resolve so they can be used to do a specific $http.get. Right now I've just tested $routeParams and passed back the param to be logged in my controller to see if it works, but it is a route behind each time. For example, on load it is undefined, and on subsequent routes the param is the previous routes param, so I click a new link and it shows the param from the previous link's route.
Route Snippet
.when('/something/:paramType', {
templateUrl: '/app/views/something.html',
controller: 'SomethingController',
controllerAs: 'someCtrl',
access: {
authentication: true
},
resolve: {
SomeData: function( $routeParams ) {
return $routeParams.paramType;
}
}
})
Controller Snippet
.controller('SomethingController', ['$scope', 'SomeData', function( $scope, SomeData) {
console.log(SomeData);
}])
How do you initialize the param on load, and have it sync correctly each time? The reason I want to do this is so I can perform an $http.get and pass the $routeParams to define the returned data.
From the angular documentation for $routeProvider
Be aware that ngRoute.$routeParams will still refer to the previous route within these resolve functions. Use $route.current.params to access the new route parameters, instead.
So..
SomeData: function( $route ) {
return $route.current.params.paramType;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With