Hi,
I’m using some BehaviorSubject in an Ionic4 app.
I’ve defined them in a service:
@Injectable({
providedIn: 'root'
})
export class DeviceManager {
public deviceSpeed: BehaviorSubject<number>;
...
}
And I’m using them in some pages in this way:
ngOnInit() {
this.devicesManager.deviceSpeed.subscribe((value) => {
// do things
}
}
I have some doubts:
- Is ngOnInit the right method in which subscribe the BehaviorSubject?
- Is unsubscribe mandatory?
- In which method should I unsubscribe the BehaviorSubject?
Thank you very much
cld
1 post - 1 participant