NG5- How to unsubscribe all the service in ngOnDestroy()
--------------------------------------------------------
To relase the component, need to unsubscribe in EveryComponent.component.ts
----------------------------------------------------------------------------
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
export class ComponentClass implements OnInit, OnDestroy
subscriptList: Array<Subscription> = [];
getServiceData(){
let subscription;
subscription = this.myService.getData(this.id).subscribe( data =>{
console.log(data)
},
(error) =>
{ console.log(error)
}
);
this.addToSubscriptList(subscription);
}
addToSubscriptList(subscription) {
this.subscriptList.push(subscription);
}
ngOnDestroy() {
this.subscriptionList.forEach(subscription => {
subscription.unsubscribe();
})
}
--------------------------------------------------------
To relase the component, need to unsubscribe in EveryComponent.component.ts
----------------------------------------------------------------------------
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
export class ComponentClass implements OnInit, OnDestroy
subscriptList: Array<Subscription> = [];
getServiceData(){
let subscription;
subscription = this.myService.getData(this.id).subscribe( data =>{
console.log(data)
},
(error) =>
{ console.log(error)
}
);
this.addToSubscriptList(subscription);
}
addToSubscriptList(subscription) {
this.subscriptList.push(subscription);
}
ngOnDestroy() {
this.subscriptionList.forEach(subscription => {
subscription.unsubscribe();
})
}
Python OpenCV Overlaying or Blending Two Images
ReplyDeletePHP File Upload MIME Type Validation with Error Handling
Detect Mobile Devices in PHP
Driving route map
Get Visitor Information by IP Address in PHP