$routeParams doesn't work in resolve function

Angularjs

Angularjs 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);
    }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionfedor.belovView Question on Stackoverflow
Solution 1 - Angularjspkozlowski.opensourceView Answer on Stackoverflow