我有一个包含很多州(和子州)的Angular应用程序。
其中一些州已经解决。
该应用程序需要两个几乎所有州共享的数据。成功登录后,将从API请求这些数据对象。
应用程序正在使用angular-jwt-tokens进行身份验证,我将令牌和有关当前用户的数据存储在$ cookieStore中,但不存储那些额外的数据。
现在出现问题:
当用户刷新页面时,我会检查令牌和用户数据是否在$ cookieStore上,如果是,请获取我需要的额外数据。
但是,如果用户刷新的状态具有依赖于该数据的解析,则会出现异常,因为应用程序会在数据进入之前启动该解析。
有没有人遇到过类似的问题?你是怎么解决的?
答案 0 :(得分:0)
Child states inherit resolves of parent states. If a parent state resolve promise gets rejected, child state resolve won't even fire.
You can basically look at the nested states having chained promises from parent state resolves ... rejections break the chain
Thus you should should be able to set up the user resolve at top level.
Also catch these in the event $stateChangeError
where you can return an appropriate alternate redirect. A run block is helpful for setting up this event listener.