5

I just upgraded to AngularFire2 rc 5.0.

I adapted my code so that it matches the new types and functions but I get the following error when trying to subscribe to a .object(path):

Property 'subscribe' does not exist on type 'AngularFireObject'

My code below.

Provider:

getEvent(id: string): AngularFireObject<any> {
    let path = `/events/${id}`;
    return this.af.object(path).valueChanges();
  }

Page:

...
event$: AngularFireObject<any>;
...

// Retrieve event's info
this.event$ = this.eventService.getEvent(this.id);

// Retrieve event's ownership info
let subscription = this.event$.subscribe(event => {
  this.owner$ = this.userService.getUserPublicInfo(event.owner);
});

Any idea?

Manuel RODRIGUEZ
  • 2,131
  • 3
  • 25
  • 53

1 Answers1

0

You are using valueChanges() meaning getEvent(id: string) is returning FirebaseObjectObservable<any> not AngularFireObject<any>. Check here.

AngularFireObject<any> is returned by this.af.object(path)

Change the return type of your function.

getEvent(id: string): FirebaseObjectObservable<any> {
    let path = `/events/${id}`;
    return this.af.object(path).valueChanges();
  }
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • When I try this, and declare `event$: FirebaseObjectObservable` compiler tells me that type FirebaseObjectObservable could not be found (I cannot not import the type... and I read that it is deprecated in 5.0). So what is the best way to handle this? I just want to map and/or subscribe as I was doing before. What's your recommendation? – Manuel RODRIGUEZ Nov 23 '17 at 12:40
  • In that case try to set return type as Observable – Suraj Rao Nov 23 '17 at 12:40
  • I have the impression that it is working. The documentation is not that clear on this point. I will resolve the other pending issues and mark as "resolved" if it works. Thx ! – Manuel RODRIGUEZ Nov 23 '17 at 12:44
  • sure :)..glad to help – Suraj Rao Nov 23 '17 at 12:45