Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Cannot GET id:0 #1499

Closed
sharkey3 opened this issue Oct 25, 2012 · 2 comments
Closed

Cannot GET id:0 #1499

sharkey3 opened this issue Oct 25, 2012 · 2 comments

Comments

@sharkey3
Copy link

For example:

angular.module('neo4j',['ngResource']).
        factory('db',function($resource){
                return $resource('http://localhost:port/db/data/node/:id',{port:':7474',id:'@id'},{
                        get: {  method:'GET',
                                headers:{'Content-Type': 'application/json',Accept: 'application/json'}}
                });

        });

function RecordController($scope,db) {
        var data = db.get({id:0});
}

results in GET "http://localhost:7474/db/data/node/" being sent instead of "/db/data/node/0"

The fix is this:

diff -u -r1.1 angular-resource.js
--- angular-resource.js 2012/10/25 23:25:34 1.1
+++ angular-resource.js 2012/10/25 23:32:14
@@ -289,7 +289,7 @@

         params = params || {};
         forEach(this.urlParams, function(_, urlParam){
-          encodedVal = encodeUriSegment(params[urlParam] || self.defaults[urlParam] || "");
+          encodedVal = encodeUriSegment(typeof params[urlParam] != "undefined" ? params[urlParam] : typeof  self.defaults[urlParam] != undefined ? self.defaults[urlParam] : "");
           url = url.replace(new RegExp(":" + urlParam + "(\\W)"), encodedVal + "$1");
         });
         url = url.replace(/\/?#$/, '');
@jakecar
Copy link

jakecar commented Oct 29, 2012

#1212 was supposed to address this issue, but is closed. I am also experiencing this bug.

@pkozlowski-opensource
Copy link
Member

Duplicate of #1212

@jakecar @sharkey3 It was already fixed in master but was not released yet. Here is a jsFiddle working with the latest version from master: http://jsfiddle.net/6G5Zf/2/

Till it is released you can grab a snapshot version of AngularJS from http://ci.angularjs.org/view/AngularJS/job/angular.js-angular-master/ws/build/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants