0
我有一个从database.php中获取数据的按钮。我试图在http.get没有响应之前添加一个超时延迟,所以我不能使用promise。在PHP中,使用sleep()很容易。至于原因,它的另一个项目模拟延迟的一部分(我知道你可以通过其他方式)。如何为每个按钮请求获取每个HTTP获取延迟超时
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;
};
});
任何想法,我可以做什么?