I have a registration mechanism in which rootscope variable is send via service. After success it updates the $rootScope.success
field. But the angularjs services is callback dependent.The service update the rootscope.success but the function sequentially execute the code.
How do i wait for service to complete its response and then further process?
.controller('RegisterAccountCtrl', function ($scope,$rootScope,registerUser,$location) {
$rootScope.success = false;
$scope.registration = $rootScope.registration;
$scope.getEnterGeneratedCode = function(){
$rootScope.registration = $scope.registration;
registerUser.registerUser();
if($rootScope.success){
$location.path('/confirm');
}
}
And inside service
.service('registerUser',function($http,$rootScope,$ionicLoading){
this.registerUser = function(){
$ionicLoading.show();
$http({
method: 'POST',
datatype:'json',
data:{obj:$rootScope.registration},
url: 'http://localhost/LoginService.asmx/CreateUser',
contentType: application/json; charset=utf-8,
cache: false
}).success(function (data, status, headers, config){
if (status == '200') {
var obj = data;
$rootScope.success = true;
$ionicLoading.hide();
//alert(obj);
}
}).error(function (data, status, headers, config){
$ionicLoading.hide();
});
};
return this;
})