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

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -