ionic3 - Angular: Data callback never stops even when unsubscribe function is used -
i trying update data api using function
ngoninit(){ setinterval(()=>{ this.getphonebook(); }, 1000); } getphonebook() { this.showphonebook = this.beaconprovider.getphonebookdirectories().subscribe(data => { this.infos = data; }, (err) =>{ console.log(err); })
}
and trying destroy using this:
ionviewdidleave(){ this.showphonebook.unsubscribe(); } ngondestroy(){ this.showphonebook.unsubscribe(); }
the problem when try destroy using ngdestroy
or attach ionviewdidleave()
lifecycle function still calls when i'm on different page. there way achieve auto update desire angularly since concern given large transaction setinterval
cause errors.
if use setinterval in component need set clearinterval.
myinterval: any; ngoninit(){ this.myinterval = setinterval(()=>{ this.getphonebook(); }, 1000); } ngondestroy(){ clearinterval(this.myinterval); }
Comments
Post a Comment