javascript - $save().then on Angular $resource doesn't wait for the service response -


i have controller , function called obtain value rest wcf web service:

foobar.controller('fooctrl',             function fooctrl($scope, $http, $resource) {                 $scope.someonclickevent = function () {                 getsomething('a','b','c');             }         } );  function getsomething($scope, $resource, a, b, c) {     var servicehandle = $resource('some/addr');     var servicehandle = new servicehandle();      servicehandle.a = a;     servicehandle.b = b;     servicehandle.c = c;      servicehandle.$save().then(function (result) {         console.log('so response should ready');         $scope.result = result.valuefromservice;     }); } 

as far know $save() returns promise , function inside .then should called right after response returned server. in case it's called imediately.

if service returns true i'm going show popup, need value returned before conditional instruction executed.

version of angular 1.4.9.

i've analysed code , behavior , i'm wrong obviously. maybe should delete question, believe can understand similar problems.

function inside .then in fact called after response comes server. can verified using instance chrome's developer tools (namely tab network).

however if after calling getsomething function want access $scope.result making great mistake. $scope.result undefined long function inside .then won't executed. use value returned service must inside .then function or in function called it.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -