路由:
.when('/view/:recipeId',{
controller:'ViewRecipe',
templateUrl:'views/viewRecipe.html',
resolve:{
recipe:['loadRecipe',function(loadRecipe){
return loadRecipe()
}]
}
})
当路由跳到 http://10.22.7.40:9000/#/view/3 的时候
使用$route.current.params为{recipeId:3},但是$routeParams却是{}
想知道原因是什么? 谢谢~
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我不知道你是在哪里查看
$routeParams的,我猜是在resolve:那里吧?这就是原因。请仔细阅读$routeParams的文档,不长,10 分钟就读完了。帮你总结一句话:然后你可以再看看文档里的这个例子,注意这个例子里模拟了异步的延迟,于是当你切换 routes 的时候,仔细观察
$route.current.params和$routeParams的变化顺序;另外看清楚这个例子是在哪里去获取$routeParams的。要学会看文档呀~
建议使用angular-ui-router插件,获取参数直接通过$stateParams即可