Angular 等待,直到触发器在firebase上以离子模式启动
在我的ionic应用程序中,我在云函数中调用Firebase身份验证触发器,这将创建一个条带客户。 创建条带客户时,它将客户id存储到Firebase实时数据库。 问题来了,条带API需要时间来创建客户。在此之前,我的execute to next语句将查找stripe的customer_id(尚未生成)和代码中断。如何使代码在创建条带用户并将客户id存储到数据库之后再转到下一条语句 注意:如果我将调试点放在控制台中,它会等待片刻,然后就会正常运行 这里是代码Angular 等待,直到触发器在firebase上以离子模式启动,angular,typescript,firebase,google-cloud-functions,stripe-payments,Angular,Typescript,Firebase,Google Cloud Functions,Stripe Payments,在我的ionic应用程序中,我在云函数中调用Firebase身份验证触发器,这将创建一个条带客户。 创建条带客户时,它将客户id存储到Firebase实时数据库。 问题来了,条带API需要时间来创建客户。在此之前,我的execute to next语句将查找stripe的customer_id(尚未生成)和代码中断。如何使代码在创建条带用户并将客户id存储到数据库之后再转到下一条语句 注意:如果我将调试点放在控制台中,它会等待片刻,然后就会正常运行 这里是代码 createacnt() {
createacnt() {
//Create Firebase account
this.customer.Email = this.customer.Email.trim();
this.afAuth.auth.createUserWithEmailAndPassword(this.customer.Email, this.user.password)
.then(userDetails => {
//Update Firebase account
this.angularDb.object("/Customers/" + userDetails.uid).update({
uid: userDetails.uid,
accountid: this.customer.AccountId,
email: this.customer.Email
}).then(success => {
// here goes the other code in whcih
// I am trying to get customer id of stripe user
this.angularDb.object('/Customers/'+userDetails.uid)
.valueChanges().take(1).subscribe((afUser:any) => {
this.user.uid = afUser.uid;
//here code breaks and syas customer_id is undefined
this.customer_id = afUser.payment_sources.customer_id;
});
});
}
在火力基地触发
exports.createStripeCustomer = functions.auth.user().onCreate(user => {
return stripe.customers.create({
email: user.email
}).then(customer => {
console.log("Stripe customer created" + customer.id);
return admin.database().ref(`/Customers/${user.uid}/payment_sources/customer_id`).set(customer.id);
});
});
您可以让客户端监听云函数预期写入的位置。这样你才能知道工作什么时候完成。不要做一次性查询。倾听结果,只有在该位置找到数据时才继续。这与您的另一个问题基本相同,不是吗?一次只问一个问题@DoughStevenson这只是为了等待所有执行,另一个是为了将数据返回到本地客户端。据我所知,这基本上是同一个问题。你能帮我展示一些客户端listner的例子吗