$routeParams doesn't work in resolve function
AngularjsAngularjs Problem Overview
I'm using this technique to load data. So I have created the following resolve function:
NoteController.resolve = {
note: function($routeParams, Note) {
return Note.get($routeParams.key);
}
}
The problems is that $routeParams.key
is undefined
at the moment of resolve
function execution. Is it correct/bug? How can I fix it?
Angularjs Solutions
Solution 1 - Angularjs
You need to use $route.current.params.key
instead. The $routeParams
is updated only after a route is changed. So your code should look along those lines:
NoteController.resolve = {
note: function($route, Note) {
return Note.get($route.current.params.key);
}
}