http({ method:'post', url:'aaa', }).success(function(data){ $scope.flag=true; }); //When the callback function does not succeed, it will not print, of course, you can also put the print in the callback function. if($scope.flag){ alert("Callback succeeded"); }
Next, look at the use of $q
$scope.call=function(){ var deferred = $q.defer(); http({ method:'post', url:'aaa', }).success(function(data){ deferred.resolve('Hello, ' + name + '!'); $scope.flag=true; }); return deferred.promise; }; //This way you can wait for the callback to succeed before printing. $scope.call().then(function(){ alert("success"); },function(){ alert("error"); });