$routeParams 在解析功能中不起作用 [英] $routeParams doesn't work in resolve function
本文介绍了$routeParams 在解析功能中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用这个加载数据的技术.所以我创建了以下解析函数:
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);
}
}
问题是$routeParams.key
在resolve
函数执行时是undefined
.它是正确的/错误吗?我该如何解决?
The problems is that $routeParams.key
is undefined
at the moment of resolve
function execution. Is it correct/bug? How can I fix it?
推荐答案
您需要改用 $route.current.params.key
.$routeParams
仅在 路由更改后更新.所以你的代码应该沿着这些线看:
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);
}
}
这篇关于$routeParams 在解析功能中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文