[英]Resolving object in state of ui-router with ui-sref
Having really big JSON object in Angular controller and ui-sref link I want to pass this object to controller of template that would be in ui-view. 在Angular控制器和ui-sref链接中有非常大的JSON对象,我想将此对象传递给将在ui-view中的模板的控制器。
I know, that I can pass parameters to state with ui-sref, but I don't want this object to appear in address bar. 我知道,我可以通过ui-sref传递参数来声明状态,但是我不希望该对象出现在地址栏中。 Also, I know that we can use 'resolve' option in state, but I can't find how to pass data to 'resolve' function from link.
另外,我知道我们可以在状态中使用'resolve'选项,但是我找不到从链接传递数据到'resolve'函数的方法。
Update
更新资料
If I use $state.go like that: 如果我这样使用$ state.go:
router configuration
路由器配置
state('social.feed.detailed',
url: '/:activityID'
templateUrl: 'views/social/detailedactivity.html'
)
in template
在模板中
<ums-social-activity ng-repeat="record in SOC_FEED_CTRL.records"
activity="record"
ui-sref-active="selected"
ng-click="SOC_FEED_CTRL.goToDetailed(record)">
</ums-social-activity>
in controller
在控制器中
$scope.SOC_FEED_CTRL.goToDetailed = (activity) ->
# here activity is real object
$state.go('social.feed.detailed', {'activityID':activity.id, 'activity':activity})
Then 'activity' param doesn't resolves at all. 然后,“活动”参数根本无法解决。
Update 2
更新2
If I modify route configuration to this: 如果我将路由配置修改为此:
state('social.feed.detailed',
url: '/:activityID?activity'
templateUrl: 'views/social/detailedactivity.html'
)
Then activity is string "[object Object]" 然后活动是字符串“ [object Object]”
You can use the ui-router
module's $state.go
function call to manually pass in $stateParams
that won't appear in the URL. 您可以使用
ui-router
模块的$state.go
函数调用来手动传递不会出现在URL中的$stateParams
。 So, rather than using the ui-sref
attribute, you'd set an ng-click
handler that calls $state.go(STATE,{'param':JSON})
. 因此,您将不使用
ui-sref
属性,而是设置一个调用$state.go(STATE,{'param':JSON})
的ng-click
处理程序。
Then, inject $stateParams
into your controller, and read 然后,将
$stateParams
注入您的控制器,并读取
$stateParams.param
To get your JSON object back. 取回JSON对象。
Chances are 机会是
ui-sref-active="selected"
Selected represents an object 选择代表一个对象
selected.name
or 要么
selected.id
Selected looks like it represents a key value relationship. 选定的内容看起来像是一个键值关系。 That is what I am experiencing anyway.
无论如何,这就是我所经历的。
<a ui-sref="itinerary.name({name:person.id})">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.