简体   繁体   English

使用ui-sref解决ui-router状态下的对象

[英]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.

相关问题 混合ui-sref和$ state.go以在Angular ui-router中进行状态转换 - Mix ui-sref and $state.go for state transition in Angular ui-router AngularJs ui-router ui-sref不使用参数从嵌套状态生成href - AngularJs ui-router ui-sref not generating href from nested state with parameter AngularJS ui-router: ui-sref 和指令 - AngularJS ui-router: ui-sref and directive AngularJS:ui-router href重写为ui-sref - AngularJS: ui-router href rewrite into ui-sref 如何在ui-router AngularJS中使用ui-sref - How to use ui-sref in ui-router AngularJS ui-router中ui-sref属性的动态更改 - Dynamic changing of ui-sref attribute in ui-router 如何使用AngularJS ui路由器构建与URL相同的URL <ui-sref> 在控制器而不是HTML中? - How to use AngularJS ui-router to build same URL as <ui-sref> in controller instead of HTML? 使用ui-router服务在离子框架中使用ui-sref和href(在哪里使用)之间的区别 - difference between using ui-sref and href(where to use) in ionic framework using ui-router service 将html插入到div中,保持ui-router ui-sref属性正常工作 - Insert html into div with angular keeping ui-router ui-sref property working AngularJS ui路由器ui-sref导致“未捕获的TypeError:无法读取未定义的属性&#39;0&#39;”错误 - AngularJS ui-router ui-sref causing “Uncaught TypeError: Cannot read property '0' of undefined” error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM