1

When user arrive to following URL

mainurl/exampleurl?token=23

i can extract the "exampleurl" using this $state.$current.name

How can i exctract the token=23 from this url

4 Answers 4

3

You can get parameters from $stateParams:

https://github.com/angular-ui/ui-router/wiki/URL-Routing#stateparams-service

var token = $stateParams.token

Hope it helps

Sign up to request clarification or add additional context in comments.

Comments

1

Option-1: You can use $location service.

 var t = $location.search().token

Option-2 If you are using ui-router, you may access the querystring parameters from $stateParams service too

var t = $stateParams.token

Cheers!

Comments

1

Try passing $location to your controller and use it like this.

.controller('YourController', ['$scope', '$stateParams', '$location' , function ($scope, $stateParams, $location) {
// Get token from query string
var token = $location.search().token;

}

Comments

0

You can get parameters with $location.search() into your controller. See below

// Given URL
// mainurl/exampleurl?token=23

var searchObject = $location.search();
// => {token: 23}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.