{"action":"opened","issue":{"url":"https://api.github.com/repos/mgonto/restangular/issues/1157","labels_url":"https://api.github.com/repos/mgonto/restangular/issues/1157/labels{/name}","comments_url":"https://api.github.com/repos/mgonto/restangular/issues/1157/comments","events_url":"https://api.github.com/repos/mgonto/restangular/issues/1157/events","html_url":"https://github.com/mgonto/restangular/issues/1157","id":81934533,"number":1157,"title":"Getting undefined result from then after get","user":{"login":"ccottrell","id":4061272,"avatar_url":"https://avatars.githubusercontent.com/u/4061272?v=3","gravatar_id":"","url":"https://api.github.com/users/ccottrell","html_url":"https://github.com/ccottrell","followers_url":"https://api.github.com/users/ccottrell/followers","following_url":"https://api.github.com/users/ccottrell/following{/other_user}","gists_url":"https://api.github.com/users/ccottrell/gists{/gist_id}","starred_url":"https://api.github.com/users/ccottrell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ccottrell/subscriptions","organizations_url":"https://api.github.com/users/ccottrell/orgs","repos_url":"https://api.github.com/users/ccottrell/repos","events_url":"https://api.github.com/users/ccottrell/events{/privacy}","received_events_url":"https://api.github.com/users/ccottrell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-05-28T13:49:21Z","updated_at":"2015-05-28T13:49:21Z","closed_at":null,"body":"This looks like an issue with the restangular javascript.. I'll explain what my problem was and what I discovered. I have this directive to validate charge codes where the method is simply returning true or false. I was of course testing where the charge code would be invalid and was getting false back in http watch, but my result variable in the then case was undefined. \r\n\r\nHere's my script below...\r\n\r\nvar deloitteChargeCodeValidator = function ($q, Restangular) {\r\n    return {\r\n        require: 'ngModel',\r\n        restrict: 'A',\r\n        link: function ($scope, element, attrs, ngModel) {\r\n            ngModel.$asyncValidators.chargeCode = function (modelValue, viewValue) {\r\n                var deferred = $q.defer();\r\n                Restangular.oneUrl('validateChargeCode', '/api/validateChargeCode').get({ chargeCode: modelValue })\r\n                        .then(function (result) {  \r\n                            deferred.resolve(result);\r\n                        }, function (reason) {\r\n                            deferred.reject(reason);\r\n                        });\r\n                return deferred.promise;\r\n            }\r\n        }\r\n    }\r\n};\r\napp.directive('deloitteChargeCodeValidator', deloitteChargeCodeValidator);\r\n\r\nOK.. So let me take you to the version that I have and where there is an issue. Should be pretty easy to see.\r\n\r\nSo from restangular.js, I see this where it is handling the response. When stepping through this, resData gets set to false as I would expect and the value of elem also gets set to false as expected. The problem lies in the fact that I'm sure you're trying to handle where the value returned is undefined so you don't restangularize stuff.. I'm sure you're seeing where I'm going.. Because elem is false, it goes to the else statement, which passes an undefined in the third parameter. I can manually force it to to take the other path debugging and then that works. The if (elem) check should check for undefined because a value of false would always force it to the else.\r\n\r\nI do have a workaround so that I can pass an object containing the value so it isn't a simple boolean, but thought I would let you know about this.\r\n\r\nvar okCallback = function(response) {\r\n                      var resData = response.data;\r\n                      var fullParams = response.config.params;\r\n                      var elem = parseResponse(resData, operation, route, fetchUrl, response, deferred);\r\n                      if (elem) {\r\n\r\n                        if (operation === \"post\" && !__this[config.restangularFields.restangularCollection]) {\r\n                          resolvePromise(deferred, response, restangularizeElem(__this, elem, what, true, null, fullParams), filledObject);\r\n                        } else {\r\n                          data = restangularizeElem(__this[config.restangularFields.parentResource], elem, __this[config.restangularFields.route], true, null, fullParams)\r\n                          data[config.restangularFields.singleOne] = __this[config.restangularFields.singleOne]\r\n                          resolvePromise(deferred, response, data, filledObject);\r\n                        }\r\n\r\n                      } else {\r\n                        resolvePromise(deferred, response, undefined, filledObject);\r\n                      }\r\n                  };"}}