Angular.js: angular-resource.js encodeUriSegment Issue .

Created on 16 Dec 2013  路  9Comments  路  Source: angular/angular.js

I have an issue querying restful resources when the resource uri has several subpaths :

Example :

.factory('SomeFactory', function ($resource) {
return $resource('/path/subPath/otherSubPath/:id', {}, {
show: { method: 'GET', params: { id: '@id' } }
})
}) ;

When I invoke SomeFactory.show in a controller I get the error
the server responded with a status of 400 (Bad Request)
This is because the browser is looking for the uri :
http://server/path/subPath%2FotherSubPat/id

Notice the %2F replacing the / (slash) in the uri , I have tried many tricks in javascript to make this work ; But the only solution was to add the following last line replace(/%2F/gi, '/'); in angular-resource.js encodeUriSegment method .

Please tell me if this approach is correct .

function encodeUriSegment(val) {
  return encodeUriQuery(val, true).
    replace(/%26/gi, '&').
    replace(/%3D/gi, '=').
    replace(/%2B/gi, '+').
    replace(/%2F/gi, '/');
}

Thanks .

ngResource invalid bug

Most helpful comment

@gkalpak I cleared cache, I used the dev js file not min version, and double check the version from the comment above, and I see clearly it is version 1.6.1, also, I just use it in my own service that calls the resources.

But good point, I see ionic.bundle.js is already copy the angular.js version 1.5.3 inside it..!

All 9 comments

I can't reproduce this with v1.2.5

see: http://plnkr.co/edit/EuxuMk9nhA9l2meKFG4d?p=preview (and check the console to see what requests it generates.

if you can create a plunker that reproduces the issue please open a new bug.

thanks!

I got the issue with angualr-resource 1.6.0. I did not find the issue in 1.5.8 .

I was getting issue in test
Error: TypeError: 'undefined' is not a function (evaluating 'encodeUriSegment(val)') at node_modules/angular-resource/angular-resource.js:576.

I changed dependencies to "angular-resource": "1.5.8" and it is working.

@ajaytiwari52, you must always use the same version of core angular and other angular modules. Mismatched versions are not guaranteed to work.

@ajaytiwari52 : where do you change the dependencies ? which file ?

package.json i chaged to angular-resource 1.5.8. using gulp

I got the issue in angular 1.6.1, while it is ok with 1.5.11:

TypeError: encodeUriSegment is not a function
    at http://localhost:8100/lib/angular-resource/angular-resource.js:576:30
    at forEach (http://localhost:8100/lib/ionic/release/js/ionic.bundle.js:13704:18)
    at Route.setUrlParams (http://localhost:8100/lib/angular-resource/angular-resource.js:570:11)
    at Function.Resource.(anonymous function) [as get] (http://localhost:8100/lib/angular-resource/angular-resource.js:737:19)

@gkalpak I have both angular and resources with version 1.6.1 inside bower, I cleaned the cache reinstalled all bower components, no luck!

I am pretty sure there is a version mismatch. Either bower is messing up or your changes are being ignored by ionic or something. Open the actual files and see what versions you are actually using.

@gkalpak I cleared cache, I used the dev js file not min version, and double check the version from the comment above, and I see clearly it is version 1.6.1, also, I just use it in my own service that calls the resources.

But good point, I see ionic.bundle.js is already copy the angular.js version 1.5.3 inside it..!

Ok, the problem is effectively the version, happen that with the update with bower or the installing angular-resource, this install the version 1.6 that is incompatible with the previous versions of angular (-1.59), and how said the friend @gkalpak And complementing what He saided, in the folder lib / ionic / js / angular we can found: angular, animate, sanitize and resource (The supported versions) for ionic and this is that we need to run ... well just we need to paste this route in our Index: