How to unsubscribe from a Firebase list in Angular2?

I am connecting to the Firebase list using

tasks: FirebaseListObservable<ITask[]>;

constructor(private af: AngularFire) {
  this.tasks = this.af.database.list("/tasks");
}

And now I want to cancel this connection when my users log out.

I already tried this.tasks.unsubscribe(), but it looks like an undefined method (I tried this because FirebaseListObservable is observable).

I also tried this.tasks.off()as suggested in the documentation, but it is also undefined.

Finally, I tried this.tasks = nulland it works, but I'm not sure if this is the correct implementation.

+4
source share
1 answer

this.tasks Observable Subscription, .

, :

let observable = Rx.Observable.interval(1000);
let subscription = observable.subscribe(x => console.log(x));
subscription.unsubscribe();

async pipe, Angular .

+7

Source: https://habr.com/ru/post/1670256/


All Articles