Friday 29 June 2018

Angular2 fire listen to node changes throws an error

THe code below was working and it should listen for changes in a node and execute a function but now am getting an error

ncaught TypeError: Object(...) is not a function
at SwitchMapSubscriber.eval [as project] (changes.js:7)

SO in my angular2 component i have

private subscriptions = new Subscription();

registered: AngularFireList<any>;
constructor(private _af: AngularFireDatabase){
     this.registered = _af.list('/registered');
 }

ngOnInit() {
    this.subscriptions.add(
        this.registered.valueChanges().subscribe(
            res => {
                console.log("the value has changed");
            }
        )
    );
}

So where am i going wrong as getting the error above which point to

angular2fire/database/list/changes

What i need my code to do is to listen to whenever there is a change in a firebase node and log to the console

The subscriptions have also been defined by

    private subscriptions = new Subscription();

AAdding it to the subscriptions then i can use onDestroy lifecycle and prevent memory leaks as shown below

    ngOnDestroy() {
      this.subscriptions.unsubscribe();
    }



from Angular2 fire listen to node changes throws an error

No comments:

Post a Comment