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.

promise result when deployed

promise result on localhost

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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -