2013-05-23 30 views
8

Bir kaynak tanımlamış:Eğik Kaynak Kodlama URL

Bence
app.factory("DatumItem", function($resource) { 
    return $resource('/data/:id', {id: '@id'}); 
}); 

Ben:

go() olarak benim denetleyicisi tanımlanır
<div ng-click="go('/datum/' + d.to_param)">Test</div> 

:

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

Söz konusu öğe için, d.param değeri

'ye eşittir. 10
TkZUOWZwcnc9Uldo%0ASzRvd2FiWk 

Ama doğru kimliği ile DatumItem.get() çağırdığınızda, bu

TkZUOWZwcnc9Uldo%250ASzRvd2FiWk 

için id değişiyor bu durumda bir% 25 kodlanmış olmaktan% önlemek için bir yol var mı ?

KoddaURI, encodeURIComponent kullanarak boş kalmayacak bir kombinasyonu denedim.

herhangi bir yardım çok takdir edilecektir, teşekkürler! URL zaten açısal geçirmeden önce bunu okumak için gerek URIencoded olduğundan

cevap

9

:

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

Bu mükemmel çalıştı, teşekkürler !! –

1

ayrıca Unescape yerine decodeURIComponent ait kullanabilirsiniz.

kod parçacığı altında bakınız -

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

Bu çözüm kullanımdan kaldırıldı, decodeURIComponent tercih edildi (p) – Leogout

0

Ben URL'yi deşifre etmek angularjs projesinde bir filtre yarattık. Örneğin URL http://www.example.com/test1 dnm2 tes3

Ardından ana uygulaması adı angularApp benim açısal projede bu- http://www.example.com/test1-test2-tes3

gibi URL'yi yapmak filtre de öyledir eğer.

var app = angular.module('angularApp', []);// This is your main angular app. 

Şimdi kod çözme url için bir filtre oluşturmak istiyorum.

app.filter('decodeURL', function() { 
    return function(text) { 
     if(text) { 
      return text.split(' ').join('-').toLowerCase().replace(/[^a-z0-9]+/g, '-'); 
     } 
    } 
}); 

Yukarıdaki kod URL kodunu çözmek için bir filtre oluşturmaktır. Ve benim filtre ismim 'decodeURL'.benim kodda bir filtre olarak decodeURL kullanacak HTML-

<a ui-sref="{{business.category[0].categoryName.toLowerCase()}}Detail({id:business.id,title:(business.title | decodeURL)})"></a> 

bu filtreyi nasıl kullanılır See the snapshot

// eyalet angularjs yönlendirme yapma üzerindedir. Yönlendiren URL için

See the snapshot

<a href="/coupon/{{coupon.id}}/{{coupon.title | decodeURL}}" 
             class="btn btn-warning show-btnhome show-button-margin">Show</a> 

// Yukarıdaki kodu.

See the snapshot