seyid yagmur seyid yagmur - 4 months ago 13
AngularJS Question

Ionic send data when routing another page

I 'got a problem.I want to send data from my home.html page to map.html page.So I am trying to pass the data from HomeController to MapController.But I don't want to use Service..
I am looking for a solution sending data simply by using $state.go or anything else...

myObject={x:"asdsad",
y:"skdfj",
....
}


$state.go('map',{"test":myObject})

do you know any solution for me?
thanks in advance!!

Answer

You've started totally right.

In you state, define the params expected, example:

.state('tab.compare-info', {
  url: '/compare/info',
  params: {
    map: null
  },
  template: '<p></p>',
  controller: 'Ctrl'
}

and call the route with

$state.go('tab.compare-info', {map: object});

Inside the destination state controller, inject $stateParam and get the parameter:

function Ctrl($stateParams) {
    var map = $stateParams.map;
}
Comments