0

How can I get the value of access_token in my ng-controller as $routeParams from the following URL?

http://www.example.com/#/access_token=asdfjaksjdhflanblasdfkjahdloahds
2
  • Ought to go through docs.angularjs.org/api/ngRoute/service/$route. You need to specify this in route and in angularjs it will be more so like /#access_token/asdafdgdhfghfgh Commented Sep 29, 2014 at 13:24
  • but I get the url as /#key=value format, not /#key/:value Commented Sep 29, 2014 at 13:31

2 Answers 2

3

on you app config

App.config(['$routeProvider', function($routeProvider) {
  $routeProvider.
  when('/:id', {
    ....
    controller: 'DetailsController'
  }).

use on your controller $routeParams

.controller("DetailsController", ['$routeParams',function($routeParams){    
    var id = $routeParams.id; // this name is from config :id
}]);
Sign up to request clarification or add additional context in comments.

2 Comments

but I get the url as /#key=value format, not /#key/:value
@TahinRahman key=value is equivalent to key:value. They're just two different conventions for the same thing.
2

If it isn't defined explicitly in your route, then it will not be available in the $routeParams

If your route is defined as:

.when('/access_token/:token')

Then you will be able to access it like this:

var token = $routeParams.token;

However, the URL you have defined isn't really a good route param, or a valid query string parameter. If it were a valid query string parameter

#/?access_token=blahblahblah

Then you could access it via the $location.search() method.

var accessToken = $location.search('access_token');

As it stands right now, you would still have to parse out the value if the entire key/value pair resides in your route param.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.