admin管理员组

文章数量:1332404

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.
I know, that I can pass parameters to state with ui-sref, but I don't want this object to appear in address bar. 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.

Update
If I use $state.go like that:
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
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]"

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.
I know, that I can pass parameters to state with ui-sref, but I don't want this object to appear in address bar. 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.

Update
If I use $state.go like that:
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
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]"

Share Improve this question edited Feb 12, 2014 at 8:41 mkrakhin asked Feb 11, 2014 at 14:40 mkrakhinmkrakhin 3,4861 gold badge23 silver badges34 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

You can use the ui-router module's $state.go function call to manually pass in $stateParams that won't appear in the URL. So, rather than using the ui-sref attribute, you'd set an ng-click handler that calls $state.go(STATE,{'param':JSON}).

Then, inject $stateParams into your controller, and read

$stateParams.param

To get your JSON object back.

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})">

本文标签: javascriptResolving object in state of uirouter with uisrefStack Overflow