2015-07-06 36 views
0

这是我的阿贾克斯请求,Angularjs Showing Loading spinner

我想显示加载微调。我提到here,但我不清楚。

我只是想在$http.post期间显示微调,并在帖子完成后隐藏。

类似于angular.element('#mydiv').show()angular.element('#mydiv').hide()的呼叫。在帖子进行过程中,我应该在哪个位置显示#mydiv

这里是我的电话

$scope.doVerify={email:'',password:''}; 
    $scope.doVerify = function() 
    { 
    email = $scope.verify.useremail; 
    password = $scope.verify.password; 
    $scope.data.show = false; 
    $http.post('VerifyUser', { email: email, password: password}).then(function (results) 
    { 
    $scope.data.show = true 
    if(results.data=='success') 
    { 
    $location.path('registration'); 
    } 
    else 
    { 
    $scope.data.msg = 'Incorrect Password' 
    } 
    }); 
    }; 

我到什么地方把angular.element('#mydiv').show()angular.element('#mydiv').hide()的装载机?

回答

1

angular.element('#mydiv').show()需要去之前,你使$ http调用和angular.element('#mydiv').hide()应该去成功和错误回调。

angular.element('#mydiv').show(); // show loading spinner 
$http.post('VerifyUser', { email: email, password: password}).then(function (results) { 
    angular.element('#mydiv').hide(); // hide loading spinner 
}); 
+0

我可以做一些像$('#mydiv')。fadeOut(100);即为了让'#mydiv'出现并慢慢消失..? – AngularAngularAngular

+0

我相信是的,只要你有你的应用程序中的jQuery。 –

+0

我可以在angularjs本身做到吗? – AngularAngularAngular

1

我认为,最好的解决办法要做到这一点是添加的微调在HTML像这样:

<div ng-show="spinnerVisibility" class="spinner></div>

,然后控制在控制器中spinnerVisibility可变前/制作后帖子。例如:

$scope.spinnerVisibility = true; 
$http.post('VerifyUser', { email: email, password: password}).then(function (results) { 
    $scope.spinnerVisibility = false; 
}); 
+0

谢谢,我可以让那个div'spinner'慢慢地出现像淡出或类似的东西吗? – AngularAngularAngular

+0

是的 - 你可以用CSS3做到这一点。只需附加/删除将执行淡入/淡出效果的类。检查了这一点http://stackoverflow.com/questions/24868844/trying-to-get-a-progress-spinner-to-fade-in-using-css – dark4p

1

这里如何在代码中显示微调器。 显示或隐藏您的img /图标$ scope.prograssing var设置。

$scope.doVerify={email:'',password:''}; 
     $scope.doVerify = function() 
     { 
     email = $scope.verify.useremail; 
     password = $scope.verify.password; 
     $scope.data.show = false; 

    $scope.sendAjax = function() { 
    $scope.prograssing = true; // show spinner here 
    $http.post('VerifyUser', { email: email, password: password}).then(function (results) 
      { 
      $scope.data.show = true 
      if(results.data=='success') 
      { 
      $location.path('registration'); 
    $scope.prograssing = false;  // hide spinner when successful 
      } 
      else 
      { 
      $scope.data.msg = 'Incorrect Password'; 
    $scope.prograssing = false;  // hide spinner when unsuccessful 
      } 
      }); 
      }; 
$scope.sendAjax(); 
     }; 
1

angular.element('#mydiv').show()需要去你的拦截器的定义中。拦截器被推入角模块的配置块内。完全是这样做的方式here

angular.element('#mydiv').hide()需要进入$ http服务的响应(在'then'块内)。

你所指的例子是完全按照它应该的方式来做的。