Standart javascript işlevi encodeURIComponent
kullanarak sorgu dizesi parametrelerini kodlamak için AngularJS bekleniyordu. şu teste göre bu durum böyle değildir: Test aşağıdaki hata nedeniyle başarısızAngularjs uri bileşenleri nasıl kodlanır
describe('$http', function() {
it('encodes uri components correctly', inject(function($http, $httpBackend) {
var data = 'Hello from http://example.com';
$httpBackend.expectGET('/api/process?data=' + encodeURIComponent(data));
$http({ method: 'GET', url: '/api/process', params: { data: data } });
$httpBackend.flush();
}));
});
:
$http encodes uri components correctly
Error: Unexpected request: GET /api/process?data=Hello+from+http:%2F%2Fexample.com
Expected GET /api/process?data=Hello%20from%20http%3A%2F%2Fexample.com
Özetle:
- Beklenen kodlama:
Hello%20from%20http%3A%2F%2Fexample.com
- Gerçek kodlama:
Hello+from+http:%2F%2Fexample.com
AngularJS ile hangi uri bileşeni (aka query string parametreleri) kodlama yöntemini beklemeliyim?
Bir şekilde angular.encodeUriQuery gibi bir şeye erişebilir miyiz? –