How to send and retrieve parameters using $state.go toParams and $stateParams?

ghz 1years ago ⋅ 912 views

Question

I am using AngularJS v1.2.0-rc.2 with ui-router v0.2.0. I want to pass the referrer state to another state so I use the toParams of $state.go like so:

$state.go('toState', {referer: $state.current.name});

According to the [docs](https://github.com/angular-ui/ui-router/wiki/Quick- Reference#stategoto--toparams--options), this should populate the $stateParams on the toState controller, but it is undefined. What am I missing?

I've created a plunk to demonstrate:

http://plnkr.co/edit/ywEcG1


Answer

All I had to do was add a parameter to the url state definition like so

url: '/toState?referer'

Doh!