Sai Kumar Sai Kumar - 12 days ago 7
AngularJS Question

Showing undefined when passing data using params in ui-router

In my controller,

$scope.register = function(index) {
$state.go('account.accountRegister', {obj: {accountType: $stateParams.accountType, accountName: $scope.data[index].accountName}})
}


In my router,

.state('account.accountRegister', {
url: '/register',
views: {
'mainView@':{
templateUrl: 'app/views/registration.html',
controller: 'registrationController',
params: {
obj: null
}
}
}

})


In my registrationController iam getting data using


$state.params.obj


But it is showing undefined. Help me if I did anything wrong here.
Thankyou.

Answer

You need to use $stateParams

.controller('registrationController', function($scope, $stateParams) {
  $scope.paramOne = $stateParams.obj;
 }

DEMO