0

Using an Observable from AngularFireFunctions' httpsCallable, the view never updates with the value even after the http request returns.

I have a simple component that uses AngularFireFunctions to make an httpCallable to a simple function. I can see the call being made in the browser's network inspector, and I have a tap(x=>console.log(x)) on the observable which does indeed log the value returned from the function. However, {personObservable | async | json} is null even after the observable has a value (the console log from the tap triggers).

Component:

import { AngularFireFunctions } from '@angular/fire/functions';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';

@Component({
 selector: 'app-simple-test',
 template: '{{personObservable | async | json}}'
})
export class SimpleTestComponent implements OnInit {

    personObservable: Observable<any> = this.fireFunctions
            .httpsCallable('getPerson')({})
                .pipe(
                    tap(person => console.log(person))
                );

    constructor(
            private fireFunctions: AngularFireFunctions) { 
    }
...

Firebase function:

import * as functions from 'firebase-functions';

export const viewInvite = 
        functions.https.onCall((data, context) => {
    return {name: "test name"};
});

As expected, a page load causes an http request to the firebase function, and the console will contain {name: "test name"} indicating that the http request worked, tap was triggered, and the observable now has a value. The page will still render "null".

I've tried replacing the httpsCallable(...)(...) with a simple of({name:"test"}), and that worked fine.

Is there something special about the Observable that httpsCallable returns that prevents the view from using its value?

Keith
  • 2,958
  • 4
  • 26
  • 29
  • i am not familiar with angualarfire. But form the rxjs side, i can't find any error. can you check in console if null is also logged, only the latest data returned will be rendered in view – JEWEL JACOB May 13 '20 at 13:35
  • I am having this exact same problem and doesn't make sense to me.Did you get to the bottom of it? – Monkeeman69 Jul 05 '20 at 01:20

1 Answers1

0

I'm not sure what's causing this weird output, but I've identified two ( not ideal ) solutions for anyone struggling with it:

1. Convert the observable toPromise() - and back to observable if you need it like that

personPromise = personObservable.toPromise();
return from(personPromise);

2. Call function via HTTP request.

Lucian Moldovan
  • 567
  • 5
  • 6