How do I parse URL params after a hash with Angularjs?

后端 未结 4 1297
挽巷
挽巷 2020-12-29 06:36

I\'m trying to parse for the access_token from Foursquare where the URL is like this:

https://mywebsite.com/4sqredirect/#access_token=1234567890XXXXX

I\'ve t

4条回答
  •  情话喂你
    2020-12-29 06:54

    From angular location service $location.hash() method return #after-hash

    so if your url is look like

    https://mywebsite.com/4sqredirect/#access_token=1234567890XXXXX
    

    then

    $location.hash() return access_token=1234567890XXXXX

    you need to split it split('=')[1]

    see this plunker when you click 4Square then $location.url() return

    /4sqredirect/#access_token=123456
    $location.hash().split('=')[1]
    

    return 123456

提交回复
热议问题