【发布时间】:2018-12-24 21:17:16
【问题描述】:
这是我的代码:
JS:
var timer;
$scope.getapi_url = function (n) {
var url = n;
$http({
method: 'GET',
url: url,
})
.then(function successCallback(data) {
$scope.data = data.data;
console.log($scope, data);
timer = $timeout($scope.getapi_url(n), 5000);
// passing n if you don't want check n value on starting of function.
}, function errorCallback(response) {
$scope.errorBackend = true;
console.log(response);
console.log('error');
});
};
HTML:
<button class="btn btn-clear btn-sm" ng-click="getapi_url('myurl') ">Click!</button>
点击getapi_url 我的$timeout 5 秒后不会超时,但就像每一刻一样。为什么?
提前谢谢解答!!!
【问题讨论】:
-
setTimeout(function () { },0);你可以用这个。