javascript - Wait for promise in RootCtrl Angular $http -



javascript - Wait for promise in RootCtrl Angular $http -

i have method in rootctrl makes phone call http api, , returns result.

$scope.checkaccess = function(){ var result = myservice.me(); result.then(function(response){ console.log(response); if (response.data != 'false'){ homecoming true; } else{ homecoming false; } }); }

but when seek phone call method in 1 of kid controllers, so...

var access = $scope.checkaccess();

it tells me access undefined.

what doing wrong here?

here service phone call looks like.

me: function() { homecoming $http({ url: 'http://localhost:5000/api/me', method: 'get' }); }

you forgot homecoming promise object.

here go:

$scope.checkaccess = function(){ var result = myservice.me(); homecoming result.then(function(response){ console.log(response); if (response.data != 'false'){ homecoming true; } else{ homecoming false; } }); }

javascript angularjs rest http angularjs-scope

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -