【发布时间】:2015-01-15 21:53:47
【问题描述】:
我这样称呼:
$state.go("main.projects.selected.dates.day", { id: $state.params.id }, {reload: true});
我真的很想将自定义数据从 state.go 函数传递到 stateChangeStart 函数。这可以通过状态参数来实现 - 我可以滥用它来接受日期对象 - 但是我的网址将无法正常工作......
如何将 state.go 中的数据传递到 stateChangeStart?仅仅通过破解 rootScope.customData 属性?
$rootScope.$on('$stateChangeStart', function (ev, toState, toParams, fromState, fromParams, injectCustomFactory here)
{
// Run custom logic here on the injected custom factory
// then change the toParams.customData property by assigning the injected value to this property.
}
为什么我必须在你可能会问的 stateChangeStart 中运行这个逻辑。
这是因为只有在那里我才能检查用户是否主动更改了 url($rootScope.customData 是假的)或者 state.go 是从外部完成的,在我执行 $rootScope.customData = MyValueLogic 之前;
【问题讨论】:
标签: angularjs angular-ui-router