在使用setInerval窗口挂
问题描述:
.controller('overviewCtrl', function ($scope, $http, $interval) {
$scope.cardShow = false;
$scope.infoShow = true;
$scope.yes1 = false;
$scope.yes2 = false;
$scope.status = true;
$scope.arbitration = true;
$scope.notAccepted = true;
$scope.cardShowRegular = false;
$scope.check1 = false;
$scope.id = 53;
$scope.opportunitiesArr = [];
$scope.opportunity = [];
$scope.profile = [];
/*getting opportunities*/
$scope.oppList = function() {
$http.get("https://serviceme.blynksystems.com:6443/createContract/fseoppurtunities/" + $scope.id)
.then(function (response) {
$scope.opportunitiesArr = response.data;
console.log("opportunities " + JSON.stringify($scope.opportunitiesArr));
}, function (response) {
console.log("error" + response);
});
}
/*$rootScope.$broadcast("sendOpportunities", $scope.opportunitiesArr);*/
$scope.oppList();
/*end of getting opportunities*/
$scope.contactInfo = function (opport) {
$scope.opportunity = opport;
console.log("opportfjdufiu" + JSON.stringify($scope.opportunity));
console.log("opport " + JSON.stringify(opport));
/*$scope.customerId = opport.customer_id;*/
/*$scope.serviceName = opport.service_name;
$scope.carModel = opport.car_model;*/
/*$scope.driverEmail = opport.driver_email;*/
/*$scope.statusOfFse = opport.status_of_fse;*/
$scope.cardShow = true;
$scope.cardShowRegular = true;
$scope.infoShow = false;
/*posting the acceptance*/
if (opport.driver_email != null || opport.driver_email != undefined) {
var data = {
"mechanic_id": $scope.id,
/*"customer_id": opport.customer_id,*/
"driver_email": opport.driver_email,
"service_name": opport.service_name,
"car_model": opport.car_model,
"status": 2,
"counter_price_fse": ""
}
} else {
var data = {
"mechanic_id": $scope.id,
"customer_id": opport.customer_id,
/*"driver_email": opport.driver_email,*/
"service_name": opport.service_name,
"car_model": opport.car_model,
"status": 2,
"counter_price_fse": ""
}
}
console.log("emergency" + JSON.stringify(data));
var req = {
method: 'POST',
url: 'https://serviceme.blynksystems.com:6443/createContract/updatewhenfseaccepted',
data: data
}
$http(req).then(function (response) {
console.log("respose" + JSON.stringify(response.data));
}, function (response) {
console.log(response);
});
$scope.callFtn = function() {
setInterval($scope.contactInfo(opport), 3000);
}
$scope.callFtn();
/*$interval(function() {
$scope.contactInfo(opport)
}, 3000);*/
/*posting the acceptance*/
}
});
我对离子project.I工作需要500秒内响应其从server.For未来,我使用后检查状态的时间间隔setinterval.But虽然使用这种方法我的窗口正在越来越strucked.I也试过setTimeOut事件,虽然同样的问题在重复。我可以如何解决这个问题。这里是我的代码:
答
你使用setInterval递归最终原因窗口卡住了。请参阅这个备用解决方案:https://*.com/a/18687829/1912288。
请在Angular中使用$interval
,因为它在调用$interval
时会查找范围更改并反映绑定中的更改。这是通过触发摘要循环完成的。
+0
谢谢。使用$ interval函数contactInfo正在调用,但函数内部的POST请求未调用。当函数内部的控制台正在打印contactInfo每3秒调用一次(除了POST请求控制台之外)时,我才知道这一点在成功块。 –
您是否看到任何错误? '$ interval'也可以。看起来有点失败 –
我已经使用了$ interval。但是在contactInfo函数iam中显示了一个div标签。在这么多时间之后div显示。 –