how can i use value changes?

The valueChanges method from firebase is an observable that return the current values, based on your query, in your realtime database. You will need to subscribe to it to get its content (if it’s not already done in the template with the async pipe).
You can add a tap operator to your observable. Each time valueChanges emit a new value, it will execute what’s in the tap operator:

this.messages = this.db.list("/forms/"+this.campId+"/chat/")
    tap(() => scrollToBottomOnInit()) 

For your second question, when your user leave the page, if you let the subscription open, it will continue to emit values. you’ll need to unsubscribe to avoid memory leak.
If you use a pipe async in your template, angular does it for you. If you subscribe to it in your component, use the ngOnDestroy method to unsubscribe:

messagesSubscription: Subscription;

ngOnInit() {
  this.messagesSubscription = this messages.subscribe();

ngOnDestroy() {

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top