3

Update2:

$location just for ng. so $location.search is ng's search it parse url from mark like # or #! .

but $window.location handle the brower url

in my question, first url's ng search is empty and second url's ng search is {code & state}

is it right?

Update1:

i found the *$window.location* got the right data. is *$location* override the all things?

Question i use angular-ui-router in my project. and i want to get search string from url, like this: http://localhost:8080/?code=123456&state=auth#/api/oauth2_authorize in app.config, i set:

$stateProvider.state("oauth2_authorize", {
            url: "/api/oauth2_authorize?code&state",
            template: "",
            controller: function($location) {
                       var search = $location.search();
            }
        })

i think the search will be { code : 123456; state:auth} but no. i try to change the url to : http://localhost:8080/#/api/oauth2_authorize?code=123456&state=auth and it work.

somebody could tell me why? the html5mode is false. i check the angularjs's document, and $location's sample show that, i can get the search string from both url. and i try to use $urlRouterProvider , but it still empty.

what can i do?

GeminiYellow
  • 1,016
  • 2
  • 12
  • 34

2 Answers2

1

Because, if you set html5mode to false, all your urls need to have #. Even if in your url state you dont have # .

For that reason http://localhost:8080/?code=123456&state=auth#/api/oauth2_authorize doesn't work and http://localhost:8080/#/api/oauth2_authorize?code=123456&state=auth it does.

Check angularjs docs for $location and urls

levi
  • 22,001
  • 7
  • 73
  • 74
0

I guess something wrong with AngularJs version you are using. Which version are you using? refer following link suggest the same issue and fix with HTML5Mode=true https://github.com/angular/angular.js/issues/6198

Or just go through following pages, may be helpful to fix your issue. https://github.com/angular/angular.js/issues/5964

https://github.com/angular/angular.js/issues/4607

Yogesh Manware
  • 1,843
  • 1
  • 22
  • 25