How to access data of [object object] AngularJS

Issue

I am new to AngularJS.
I am sending a JsonObject to another state.

Ex:

viewScope.edit=function(d) {

   var viewData = {
      'name' : d.name,
   };

   $state.go('edit', {'viewD': viewData}, {reload: true});
};

My State is-

viewApp.config(function($stateProvider){
    $stateProvider
        .state('edit', {
            name: '#/edit',
            url: '/register/{viewD}',
            templateUrl: function(){    
                 return path+'/register.jsp';
             },
             controller:'registerCtrl',
             resolve : {
                 loadPlugin: function($ocLazyLoad) {
                     return $ocLazyLoad.load([{
                         name : 'registerApp',
                         files: [path+'/resources/js/register.js'],
                     }])
                }
            }
        })
});

In register Controller getting data-

regApp.controller('registerCtrl',function($stateParams){                 
        if($stateParams != undefined){
            console.log($stateParams.viewD);
        }
});

On console output is- [object object]

How can i access the name key from this [object object].

console.log($StateParams.viewD.name); // Not Working

JSON.parse, JSON.stringify not working.

Solution

You have to change your state config URL from

url: '/register/{viewD}',

to

url: '/register/{viewD:json}',

The JSON parameter type has been added in version 0.2.13

Answered By – Weedoze

Answer Checked By – Marilyn (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.