【发布时间】:2017-05-21 14:57:33
【问题描述】:
我有一个从 database.php 获取数据的按钮。我试图在 http.get 没有响应之前添加超时延迟,所以我不能使用承诺。在 php 中,使用 sleep() 非常简单。至于原因,它是另一个模拟延迟的项目的一部分(我知道你可以通过其他方式做到这一点)。
app.controller('mainController', function ($scope, $http, $timeout) {
$scope.requestData = function () {
$scope.delta = '[waiting]';
//Delay here!
$http.get('database.php').then(function (response) {
$scope.rows = response.data.records;
};
});
我试过了,不行:
app.controller('mainController', function ($scope, $http, $timeout) {
$scope.requestData = function () {
$scope.delta = '[waiting]';
$http.get('database.php',{ timeout: 3000 }).then(function (response) {
$scope.rows = response.data.records;
};
});
我试过传递一个空的计时器,不起作用:
app.controller('mainController', function ($scope, $http, $timeout) {
var timer = function () {
}
$scope.requestData = function () {
$scope.delta = '[waiting]';
$timeout(timer, 3000);
$http.get('database.php').then(function (response) {
$scope.rows = response.data.records;
};
});
有什么想法,我能做什么?
【问题讨论】:
标签: angularjs http timeout delay