$ routeParams不解决功能工作 [英] $routeParams doesn't work in resolve function

查看:209
本文介绍了$ routeParams不解决功能工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用<一个href=\"http://stackoverflow.com/questions/11972026/delaying-angularjs-route-change-until-model-loaded-to-$p$pvent-flicker\">this技术加载数据。所以我创建了下面的决心功能:

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 未定义的瞬间化解函数执行。它是正确/错误?我怎样才能解决这个问题?

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 只的之后的路线改变更新。所以,你的code应该沿着这些线路看:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆