1

I Would like to pass two object in state.go method like this:

$state.go('app.home', {
            playSavedPlaylist:true,
            playlistData: dataToPass
        });

State app.home is following:

.state('app.home', {
      url: '/home:playSavedPlaylist:playlistData',
      views: {
        'menuContent' :{
          templateUrl: 'templates/home.html',
          controller: 'HomeCtrl'
        }
      }
    })

But if i'm trying to get params using:

console.log($stateParams);

I always get following:

Object {playSavedPlaylist: "true[object Object]", playlistData: ""}

But should it be:

  Object {playSavedPlaylist: "true", playlistData: [object Object]}

How can i do it in right way please?

Many thanks for any advice.

redrom
  • 11,502
  • 31
  • 157
  • 264

2 Answers2

2

You can add '/' to separate between parameters. Also url parameters can only be integers and strings, therefore objects must be converted to json, or not being included in the url.

.state('app.home', {
    url: '/home/:playSavedPlaylist/:playlistData',
    views: {
        'menuContent' :{
            templateUrl: 'templates/home.html',
            controller: 'HomeCtrl'
        }
    }
});

$state.go('app.home', {
    playSavedPlaylist:true,
    playlistData: angular.toJson(dataToPass)
}
//, { location: false, inherit: false}    <-- will exclude parameters from url
);
devqon
  • 13,818
  • 2
  • 30
  • 45
0

What is dataToPass ? an object?

You can't pass an object directly in the URL, so you should use a service in order to get the data that you need, you can only pass integer (ex: id, max, min) and string that doesn't contains forbidden char for URL (You can use URI encode).

Mathieu Bertin
  • 1,634
  • 11
  • 11