2017-08-04 8 views
0

私は角度ui-routerを使用しています。 $stateParamsをbase64エンコードでエンコードしたいと思います。たとえば、次のように

http://example.com/profile/6013/details

我々はbtoa() FUNCを使用Base64形式の文字列をエンコードするために

答えて

0
$scope.go = function (params) { 
    $location.path(decodeURIComponent(params)); 
}; 

<!DOCTYPE html> 
 
<html> 
 
<body> 
 

 
<p>Click the button to encode a URI.</p> 
 

 
<button onclick="myFunction()">Try it</button> 
 

 
<p id="demo"></p> 
 

 
<script> 
 
function myFunction() { 
 
    var uri = "my test.asp?name=ståle&car=saab"; 
 
    var res = encodeURI(uri); 
 
    document.getElementById("demo").innerHTML = res; 
 
} 
 
</script> 
 

 
</body> 
 
</html>

0

http://example.com/profile/kfnvjodu==/details

atob()関数を使用して同じエンコードされた文字列をデコードします。

例:あなたはこのようにエンコードする場合

var x="angular js"; 
var encodedString = btoa(x); // result: YW5ndWxhciBqcw== 
var decodedString = atob(encodedString);// result: angular js 

ので"http://example.com/profile/"+btoa(6013)+"/detials"はこのURL http://example.com/profile/NjAxMw==/detials

あなたになります
関連する問題