Winnemucca
Winnemucca

Reputation: 3458

passing multiple values with ui-router ui-sref

I am calling state on the ui-sref with limited success.

I am able to get back the person.id value. I am seeking to get back all values off of the key object.

   $stateProvider.state('itinerary', {
        url: '/itinerary',
        views: {
            "main": {
                controller: 'ItineraryCtrl',
                templateUrl: 'src/app/itinerary/itinerary.tpl.html'
            },
            resolve: {
                 dates: ['$stateParams', function($stateParams){
                console.log('name',$stateParams);
                return $stateParams.dates;
                }]
            }
        },
        data: {
            pageTitle: 'Itinerary'
        }
    });

is there a way to get all properties of the object to pass?

Here is the html tag that I am using

<td><a ui-sref="itinerary.name({name:person.id, details:person.dates})">{{person.name}}</a></td>

Upvotes: 1

Views: 2193

Answers (1)

hansmaad
hansmaad

Reputation: 18905

Params should be defined on the URL, so you get consitent behaviour if loading state from ui-sref, $state.go or by typing in the URL. In this case params have to be strings.

$stateProvider.state('itinerary', {
    url: '/itinerary/:name/:details',
    // ... 
});

You can pass objects to a state, but this won't work when loading state from URL. To do this, define your params in the params property:

$stateProvider.state('itinerary', {
    url: '/itinerary/:name',  // name from URL
    params: {
         details: null        // details object
    },
    // ... 
});

Upvotes: 2

Related Questions