【发布时间】:2020-01-10 14:49:07
【问题描述】:
我正在研究 ionic 4 和 angular。我的应用程序是航班时刻表的内容。如果特定航班到达,我想做的是从我的服务器接收本地通知。 l 使用setInterval重新加载服务器以检查航班是否到达。问题是当航班到达时setInterval仍在重新加载,我也使用了clearInterval但没有停止。
async ActiveNotif() {
this.ng.run(() => {
// reloading
this.interval= setInterval(()=>{
this.http.get('flight=' + this.id + '', {}, {})
.then(data => {
let FlightDetails = JSON.parse(data.data);
this.identification = FlightDetails.identification.callsign;
this.Fstatus = FlightDetails.status.generic.status.text;
console.log(this.Fstatus)
});
//checking
if (this.Fstatus == "landed") {
this.localNotifications.schedule(
[
{
id:0,
title: 'Your flight has arrived',
text: 'Your flight ' + this.identification + 'is arrived',
trigger: { count: 1 },
sound: "file://assets/one.mp3"
},
]);
}
},10000)
if (this.Fstatus == "landed") {
clearInterval(this.interval)
}
})
}
【问题讨论】:
标签: angular setinterval ionic4 reload