0

In angularjs ng-route since my params are dynamic i'm passing it as json like as shown below

$scope.filmNames= {
            'films': {
                    'film': [{
                        filmName: 'ABCD',
                        filmYear: '123'
                    }, {
                        filmName: 'BCD',
                        filmYear: '145'
                    }, {
                        filmName: 'DEF',
                        filmYear: '128'
                    }]
                }
            };

'.../index.html#/admin?jsonObj='+$scope.filmNames

ans it succesffully sending as like

http://localhost:8000/index.html#/admin?jsonObj=[object Object]

but at the controller receiver when i tried to get it through using $routeParams like

var jsonObj= $routeParams.jsonObj;

console.log(JSON.stringify(jsonObj));

It is been printing it as "[object Object]", instead of the values

can anyone please tell me solutions for this

Alex Man
  • 4,746
  • 17
  • 93
  • 178

1 Answers1

5

When you convert an object to a string using concatentation, you get: [object Object]. What you actually want is to convert the object to json.

'.../index.html#/admin?jsonObj='+JSON.stringify($scope.filmNames)

Then, at the receiver, you'll want to parse it, not stringify it.

console.log(JSON.parse(jsonObj));

I suggest moving away from calling json strings "json objects", it just leads to confusion. json strings don't always represent objects.

Kevin B
  • 94,570
  • 16
  • 163
  • 180