Я делаю запрос $http
, когда пользователь нажимает кнопку <button>
, и я отключаю/скрываю/показываю несколько элементов на экране, пока запрос не вернется с помощью success
или error
Есть ли способ узнать, что $http
еще не получил ответа? То, как я делаю это прямо сейчас, это у меня есть var в моем контроллере под названием $scope.requesting
, который затем я использую на своей HTML-странице так:
<img src="img/loader.gif" ng-show="requesting" />
так что в основном, когда $scope.requesting
истинно, покажите спиннинг ajaxyish loader.
Я хотел бы по возможности отключить $scope.requesting
и использовать любое $http
, если оно вообще есть.
Контроллер входа
function LoginForm($scope, $http)
{
$scope.requesting = false;
$scope.login = function()
{
$scope.requesting = true;
$http.post('resources/request.php', data, {timeout:20000})
.success(function(data, status, headers, config)
{
$scope.requesting = false;
})
.error(function(data, status, headers, config)
{
$scope.requesting = false;
}
);
}
}