2015-10-07 48 views
1

我是一個初學者到Angular JSSalesforce技術。如何獲取網址參數,當它開始與#?

有一個salesforce的API,它返回結果如下。

http://localhost:63342/www/index.html#/#access_token=access_token&refresh_token=refresh_token&instance_url=url&id=id&issued_at=1444216583754&signature=sign&scope=scope&token_type=Bearer 

這裏,URL參數開始以哈希(#)

如果將與問號(?)開始

http://localhost:63342/www/index.html#/?access_token=access_token&refresh_token=refresh_token&instance_url=url&id=id&issued_at=1444216583754&signature=sign&scope=scope&token_type=Bearer 

那麼我可以簡單地使用$location.search方法,但銷售人員沒有迴應這樣的說法。

所以我的問題是訪問Angular JS中的URL參數。


編輯:

我用$location.hash它給了我如下結果:

#/#access_token=access_token&refresh_token=refresh_token&instance_url=url&id=id&issued_at=1444216583754&signature=sign&scope=scope&token_type=Bearer 

我也試過$location.hash.acess_token但不工作。

我想訪問個人蔘數,有沒有辦法做到這一點?

回答

0

#之後的部分稱爲散列。所以,你可以在window.location.hash找到它或角,你會發現它在$location.hash()

+0

謝謝!幫了很多忙。 –

0

使用在JavaScript window.location.hash

0

使用這樣的腳本

<script> 
     var app = angular.module('queryStringApp', []); 
     app.controller('firstCtrl', function($scope, $location) { 
     alert("Account Number is - "+ $location.search()['accountNo']); 

     $scope.accountNo=$location.search()['accountNo']; 
     }); 
    </script> 

檢查plunkr http://plnkr.co/edit/TNX06WFx0n6p1mSLPKfP?p=preview

+0

正如我在我的網址中提到的,沒有'?',而是有一個'#',所以這種方法是不適用的。 –