Make function wait for $http response in AngularJS
问题 I have a method seatClicked() that calls getUserID() to get the user id corresponding to the session atribute 'user'. There is a table that contains the username and user id(unique). The following is the definition of seatClicked() $scope.seatClicked = function() { promise = $scope.getUserID(); promise.then(function(results){ $scope.seatID.userID = results; // store the user id in $scope.seatID.userID }); } This is the definition for getUserID() $scope.getUserID = function() { var deferred =