Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
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]"

like image 859
mkrakhin Avatar asked Feb 11 '14 14:02

mkrakhin


2 Answers

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.

like image 177
citizenslave Avatar answered Sep 28 '22 00:09

citizenslave


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})">
like image 22
Winnemucca Avatar answered Sep 28 '22 00:09

Winnemucca