Angularfire: Executing " “callable functions” using angularfire2

Created on 21 Jul 2018  Â·  10Comments  Â·  Source: angular/angularfire

Callable functions in firebase can be executed as below:

firebase.functions().httpsCallable('addMessage');
I am wondering what is the equivalent of this in AngularFire2. I have scanned the documents and don't see any mention of this.

If there is no equivalent then how do i obtain a handle to underlying firebase object in AngularFire2 ?

Most helpful comment

An update to @lenanex's code for anyone else that is having problems.

this.functions.httpsCallable('functionName')({ text: 'Some Argument' })
  .toPromise()
  .then(resp => {
    console.log({ resp });
   })
  .catch(err => {
    console.error({ err });
  });

All 10 comments

It looks like as of RC9 they added this ability through a new module called AngularFireFunctionsModule (I was literally just coming to this repo to look for this ability as well)

You can import that module with all the other angularfire ones and then use the AngularFireFunctions object exported from it in your component. There's no documentation but it looks like there's a method called httpsCallable just like in the firebase sdk. I assume it is just a wrapper around that same method.

It seems to be working but it's not :)

constructor(public db: AngularFirestore, public functions: AngularFireFunctions) {} getData(id){ var getData = this.functions.httpsCallable('getData'); return getData({id: id}).then((result) => console.log(result)).catch((e)=> console.log(e)); }
Doing this, sends the HTTPS request to the server but I have a "Response for preflight is invalid (redirect)" error then...

We are getting docs on this soon!

@lenanex , @atinybeardedman @runtimeZero try Angularfirebase's example : https://angularfirebase.com/lessons/saas-metered-subscriptions-with-stripe-billing-and-firebase/

There's an implementation that can help.

@davideast Any idea why the angularfire2 wrapper converts the Promise returned from the native API to an Observable? A Promise seems to make more sense, which means any consumer needs to convert the Observable back to a Promise with Observable.toPromise, as is shown in the example posted by @pradt above.

An update to @lenanex's code for anyone else that is having problems.

this.functions.httpsCallable('functionName')({ text: 'Some Argument' })
  .toPromise()
  .then(resp => {
    console.log({ resp });
   })
  .catch(err => {
    console.error({ err });
  });

If you want a Promise, you can just use the vanilla Firebase API. No?

On Sun, Sep 2, 2018, 2:29 AM madakk notifications@github.com wrote:

@davideast https://github.com/davideast Any idea why the angularfire2
wrapper converts the Promise returned from the native API to an Observable?
A Promise seems to make more sense, which means any consumer needs to
convert the Observable back to a Promise with Observable.toPromise, as is
shown in the example posted by @pradt https://github.com/pradt above.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/angular/angularfire2/issues/1789#issuecomment-417916872,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AACvr7dTvKhs6cljeip9DiA8V8A3kU88ks5uW6TngaJpZM4VZn4M
.

Of course, but why have the wrapper convert it to an Observable if the API returns a Promise?

Observable indicates that the state might change after request - but it's always final.

Not if it's a single. The idea is to allow it to be pipelined, including
our own zone pipelining.

Observables are very much the first class citizen in Angular. That's the
whole idea behind this library, else why use it at all?

On Mon, Sep 3, 2018, 9:50 PM Michael Kimpton notifications@github.com
wrote:

Of course, but why have the wrapper convert it to an Observable if the API
returns a Promise?

Observable indicates that the state might change after request - but it's
always final.

—
You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/angular/angularfire2/issues/1789#issuecomment-418240393,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AACvr0pII8vcmbWxjepQPJYtu8PgkyQOks5uXgajgaJpZM4VZn4M
.

Docs are up.

Was this page helpful?
0 / 5 - 0 ratings