javascript - Angular promise difference localhost vs deployed -
i'm doing call rest service returns true or false.
function toplevelclosed($stateparams) { var id = $stateparams.id; return id ? traject.toplevelclosed({id: id}).$promise : false; } var toplevelclosed = { method: 'get', url: trajecturl + ':id/toplevelclosed' };
toplevelclosed $resource method. works localhost. toplevelclosed var 'false', equal value returned rest call. when deployed (to google app engine), result "wrapped in promise" seen in image below. when call rest-service through browserwindow, returns false should.
why won't work when deployed?
the behavior describe expect code. when function returns promise call
toplevelclosed($stateparams).then(function(value){ /* value */ });
if instead toplevelclosed returns boolean can access value directly without then(...)
.
to consistent behavior return promise, this:
function toplevelclosed($stateparams) { var deferred = $q.defer(); if(id){ traject.toplevelclosed({id: id}).$promise.then(function(value){ deferred.resolve(value); }); } else { deferred.resolve(false); } return $q.promise; }
well isn't pretty hoped can improve it. recommend use consistent return type. when mix booleans , promises have analyze return value's type before continuing.
Comments
Post a Comment