Swamy Reddy Swamy Reddy - 5 months ago 5x
AngularJS Question

How to pass data through states in AngularJs?

I am building a multi step signup form, in that I am passing the data
from 1st state to 2nd state using input boxes, but data is not
fetching from the first state

var publisherdata = {
email: $scope.publishersignup.email,
name: $scope.publishersignup.name,
password: $scope.publishersignup.password
$state.go('profile', publisherdata);

in html view I am using this publisherdata variable to fetch the details like:

<input type="text" ng-model="email" ng-bind="publisherdata.email" name="email" disabled />

But value is nothing. Please help, how to pass data?


For the bindings to work, you need to define your data as state parameters, inject $stateParams in your destination controller and add the parameters into $scope.

For example,

State configuration:

$stateProvider.state('profile', {
   url: '/profile',
   params: {
     publisherdata: null
   templateUrl: '',
   controller: 'destinationCtrl'

Passing data:

$state.go('profile', {
 publisherdata: {
  email: $scope.publishersignup.email,
  name: $scope.publishersignup.name,
  password: $scope.publishersignup.password

Destination controller:

.controller('destinationCtrl', function($scope,$stateParams){
  $scope.publisherdata = $stateParams.publisherdata;