幕布斯6054654
2019-03-21 18:15:52
路由:.when('/view/:recipeId',{ controller:'ViewRecipe', templateUrl:'views/viewRecipe.html', resolve:{ recipe:['loadRecipe',function(loadRecipe){ return loadRecipe() }] } })當(dāng)路由跳到 http://10.22.7.40:9000/#/view/3 的時(shí)候使用$route.current.params為{recipeId:3},但是$routeParams卻是{}想知道原因是什么? 謝謝~
1 回答

哈士奇WWW
TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超6個(gè)贊
我不知道你是在哪里查看 $routeParams
的,我猜是在 resolve:
那里吧?這就是原因。請仔細(xì)閱讀 $routeParams
的文檔,不長,10 分鐘就讀完了。幫你總結(jié)一句話:
Note that the
$routeParams
are only updated after a route change completes successfully. This means that you cannot rely on $routeParams being correct in route resolve functions.
然后你可以再看看文檔里的這個(gè)例子,注意這個(gè)例子里模擬了異步的延遲,于是當(dāng)你切換 routes 的時(shí)候,仔細(xì)觀察 $route.current.params
和 $routeParams
的變化順序;另外看清楚這個(gè)例子是在哪里去獲取 $routeParams
的。
要學(xué)會(huì)看文檔呀~
添加回答
舉報(bào)
0/150
提交
取消