gpt4 book ai didi

javascript - 如何在 Angular 中使用 $interval 进行连续轮询?

转载 作者:行者123 更新时间:2023-11-28 06:47:04 25 4
gpt4 key购买 nike

在我的 Angular 代码中,我有一个用于长轮询的代码,如下所示

var request = function() { 
$http.post(url).then(function(res) {
var shouldStop = handleData(res);
if (!shouldStop()) {
request()
}
};
}
request();

页面加载后立即调用该函数。

但是,现在我尝试在 Protractor 中设置测试,但收到此错误消息

Failed: Timed out waiting for Protractor to synchronize with the page after 11 seconds. Please see https://github.com/angular/protractor/blob/master/docs/faq.md. The following tasks were pending:

docs ,我读了以下内容:

Before performing any action, Protractor asks Angular to wait until the page is synchronized. This means that all timeouts and http requests are finished. If your application continuously polls $timeout or $http, it will never be registered as completely loaded. You should use the $interval service (interval.js) for anything that polls continuously (introduced in Angular 1.2rc3).

我应该如何编辑代码以使用 $interval?我认为interval是window.setInterval的 Angular 包装器,我不知道如何使用它进行长轮询。

最佳答案

哦,文档中的 $interval 属于 $timeout,而不是 $http

好吧,我将抛弃 Angular 的 $http 并仅使用 fetch (带有额外的 $rootScope.$apply 和 JSON 反序列化)做同样的事情

关于javascript - 如何在 Angular 中使用 $interval 进行连续轮询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33319594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com