angularjs wait for response from $http -


i have problem function doesn't wait response of http request , go further. know can use promise wait don't understand concept.

i have data service have http request :

function getgroupidfrombakery(bakeryid, successcallback, errorcallback) {         $http.get(service.baseurl + "bakeriesgroup/bakeries/" + bakeryid)             .then(function (result) { successcallback(result.data); }, errorcallback);     } 

from service, call data service :

var haspermission = function (permission, params) {             permissionroute = permission;             setidentity(params);             (var = 0; < permissions.length; i++) {                 if (permissionroute.name === permissions[i].name) {                     if (permissions[i].scope == "system")                         return true;                     else if (permissions[i].scope == permissionroute.scope && permissions[i].identity == permissionroute.identity)                          return true;                 }             }             return false;         }    var setidentity = function (params) {             if (permissionroute.scope == "bakery")                 permissionroute.identity = parseint(params.bakeryid);             else if (permissionroute.scope == "group") {                 if (params.bakeriesgroupid)                     permissionroute.identity = parseint(params.bakeriesgroupid);                 else {                     getgroupofbakery(parseint(params.bakeryid));                    }                  console.log(permissionroute.identity);             }         }  var getgroupofbakery = function (bakeryid) {             dataservice.getgroupidfrombakery(bakeryid, function (groupid) {                 permissionroute.identity = groupid;             }, function (error) {                 console.error("something went wrong while getting bakery");                 alert("une erreur s'est produite lors de la récupération de la boulangerie");             });          } 

i must wait response of dataservice.getgroupidfrombakery(). code, permission.entityid undefined when call getgroupbybakery().

can me, please?

you can add watcher response data. think entityid in case. executed entityid changes. after getting response data can call function, time entityid not undefined.

$scope.$watch(function () {             return entityid           }, function (newentityid) {             if(newentityid != undefined {                 // can call function              }             }         }, true); 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -