Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49082

Which is the beast way to use BehaviorSubject with Ionic4?

$
0
0

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

Read full topic


Viewing all articles
Browse latest Browse all 49082

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>