I am facing an issue as :: Uncaught Type Error: Cannot read property 'unsubscribe' of undefined.I applied a lot of fixes available on the net but still couldn't get rid of the issue.I also logged the object in console during debugging the code. The subscription object is available and is not in closed state , but when it hits the ngdestroy() method its gets undefined.Please help me out.Below is my code :
Initializing :
downloadSubscription: Subscription= new Subscription();
uploadSubscription: Subscription= new Subscription();
Assigning the Observable:
this.uploadSubscription = this._apiService.uploadFile(jsonData).subscribe(response => {
this.showAlertMessage(true, 'success', response.RESPONSE);
}, Error => {
console.log('ErrorMessage:' + Error +
' Current Request' + JSON.stringify(this.Upload.filename) + 'File At Post Method.');
this.showAlertMessage(true, 'error', 'Unable to upload File.Please try again.');
});
NGDestroy method
ngOnDestroy() {
console.log('unsubscribing observables');
// unsubscribing to prevent memory leaks.
this.uploadSubscription.unsubscribe(); }