等待两个订阅结束

时间:2019-08-14 23:01:02

标签: javascript angular firebase firebase-realtime-database angularfire2

我有两个这样的订阅:

this.birthdays = await this.birthdaySP.getBirthdays();
this.birthdays.subscribe(groups => {
    const allBirthdayT = [];
    groups.map(c => {
      allBirthdayT.push({
        key: c.payload.key, 
        ...c.payload.val()
      })
    })

    console.log(allBirthdayT);
});

this.birthdaysInGroups = await this.birthdaySP.getBirthdaysInGroups();
this.birthdaysInGroups.subscribe(groups => {
    const allBirthdayB = [];
    groups.map(c => {
      c.birthdays.subscribe(d => {
        d.map(e => {
          allBirthdayB.push(e);
        })
      })
    })

    console.log(allBirthdayB);
});

我想等待这两个订阅的结尾,比较allBirthdayB和allBirthdayT数组(我在两个console.log中接收数据)。

this.birthdaySP.getBirthdays() this.birthdaySP.getBirthdaysInGroups()是两个从Firebase接收数据的可观察对象。

第一个Observable就是这样:

async getBirthdays() {
   const user = await this.authSP.getUserInfo();
   return this.angularFire.list('birthdays', ref => ref.orderByChild('creator_user_id').equalTo(user.uid)).snapshotChanges();
}

我尝试使用forkJoin,但我不知道如何使用它来解决此问题

有什么提示吗?

1 个答案:

答案 0 :(得分:0)

您可以使用<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>You're Invited to the SAP SuccessFactors SuccessConnect in Las Vegas</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="ProgId" content="Word.Document"> </head> <body style="margin:0; padding:0;" bgcolor="#ffffff" link="#008cd2"> <style type="text/css"> * { -webkit-text-size-adjust: none; -webkit-text-resize: 100%; text-resize: 100%; } </style> <!-- main wrapper --> <table data-section="body" class="wrapper" width="100%" cellspacing="0" cellpadding="0" bgcolor="#ffffff"> <!-- header --> <tr> <td> <table data-section="header" class="wrapper" width="100%" cellspacing="0" cellpadding="0" bgcolor="#ffffff"> <tr> <td style="font-size:1px;color:#FFFFFF;"> <font color="#FFFFFF" style="font-size:1px;color:#FFFFFF;line-height:0;"> <!-- inbox preview optimized text --> <span class="appleLinksWhite">Join SAP in Las Vegas for SuccessConnect at the Aria Resort! Hear from HR industry thought leaders, experts, and special guests.</span> </font> </td> </tr> <tr> <td> <table class="container header-container" title="header-container" width="640" align="center" cellpadding="0" cellspacing="0" bgcolor="#000000" style="margin:0 auto !important; padding:0 20px;"> <tr> <td> <table width="100%" cellspacing="0" cellpadding="0"> <tr> <td height="17" class="height10" style="line-height:1px; font-size:1px;">&nbsp;</td> </tr> <tr> <td> <table width="100%" cellspacing="0" cellpadding="0" title="brand"> <tr> <td valign="middle" width="414" style="line-height:1px; font-size:1px;"><img src="https://portal.thinkwgroup.com/html-email/sap/email/images/logo-carlyle-group.png" alt="" border="0" style="vertical-align:top; width: 201px; height: 36px;"></a> </td> <td valign="middle" align="right" width="104" style="line-height:1px; font-size:1px;"> <a title="THE BEST RUN" href="https://www.sap.com" style="text-decoration:none;"><img src="https://fm.sap.com/images/2015/run-simple-email/TheBestRunLogo-64px-White-DG.png" alt="THE BEST RUN" border="0" hspace="0" vspace="0" width="104" height="32" title="tagline" style="vertical-align:top; width: 104px; height: 32px;"></a> </td> <td width="10" class="hide" style="line-height:1px; font-size:1px;">&nbsp;</td> <td valign="middle" align="right" width="72" style="line-height:1px; font-size:1px;"> <a title="SAP" href="https://www.sap.com" style="text-decoration:none;"><img src="https://fm.sap.com/images/2015/run-simple-email/logo.png" alt="SAP" border="0" hspace="0" vspace="0" width="72" height="36" title="logo" style="vertical-align:top; width: 72px; height: 36px;"></a> </td> </tr> </table> </td> </tr> <tr> <td height="17" class="height10" style="line-height:1px; font-size:1px;">&nbsp;</td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </td> </tr> <!-- main --> <tr> <td> <table data-section="main" class="wrapper" width="100%" cellspacing="0" cellpadding="0" bgcolor="#ffffff"> <tr> <td> <table class="flexible" width="640" align="center" cellpadding="0" cellspacing="0" style="margin:0 auto !important;"> <tr data-section="hero"> <td> <table class="flexible" width="640" align="center" cellpadding="0" cellspacing="0" style="margin:0 auto !important;"> <tr class="motion-row"> <td width="100%" valign="top" bgcolor="#000000"> <table background="https://portal.thinkwgroup.com/html-email/sap/email/images/banner-lasvegas.jpg" width="100%" cellspacing="0" cellpadding="0"> <tr> <td style="line-height:1px; font-size:1px;" height="60">&nbsp;&nbsp;</td> </tr> <tr> <td style="font:36px/44px Arial, Helvetica, sans-serif; color:#ffffff;"> <span class="font22">Join SAP in Las Vegas for Success<span style='color:#f0ab00;'>Connect</span> at the Aria Resort!</span><br> </td> </tr> <tr> <td align="left" width="50" height="40"> <a class="font14" style="font: 18px Arial, Helvetica, sans-serif; color: #ffffff; text-align: center; text-decoration: none; background:#008fd3; display: inline-block; line-height: 40px; padding: 0 1em;" href="https://events.sap.com/gb/cx-live-2019-london/en/registration.aspx?cid=10902&autoplay=off" target="_blank" data-sap-hpa-ceimo-ioi-link="73554900100700000840">Register today</a> </td> </tr> <!-- main <tr> <td class="widthAuto mceEditable" style= align="center" valign="middle" bgcolor="#008fd3" width="250" height="40"><a class="font14" style="font: 18px/18px Arial, Helvetica, sans-serif; color: #ffffff; text-align: center; text-decoration: none; display: block;" href="https://events.sap.com/successconnect/en/las-vegas-2019" target="_blank" data-sap-hpa-ceimo-ioi-link="73555000100800000773">Register today &rsaquo;</a></td> </tr> --> <tr> <td style="line-height:1px; font-size:1px;" height="40">&nbsp;</td> </tr> <tr> <td style="line-height:1px; font-size:1px;" height="40">&nbsp;</td> </tr> </table> </td> </tr> </table> </td> </tr> <tr> <td height="30" style="line-height:1px; font-size:1px;">&nbsp;</td> </tr> <tr data-section="subhead"> <td> <table class="container" width="640" align="center" cellpadding="0" cellspacing="0" style="margin:0 auto !important; padding:0 20px;"> <tr> <td align="left" style="font:22px/30px Arial, Helvetica, sans-serif; color:#444444;"> <span class="font19">Hear from HR industry thought leaders, experts, and special guests.</span> </td> </tr> </table> </td> </tr> </table> <table class="container" width="640" align="center" cellpadding="0" cellspacing="0" style="margin:0 auto !important; padding:0 20px;"> <!-- email body --> <tr> <td> <table width="100%" cellspacing="0" cellpadding="0"> <tr data-section="content"> <td> <table width="100%" cellspacing="0" cellpadding="0"> <tr> <td style="font:14px/21px Arial, Helvetica, sans-serif; color:#444444;"> <p>You are cordially invited to attend our annual&nbsp;SuccessConnec<u>t</u>&nbsp;event, held by SAP SuccessFactors this September 16&ndash;18 in Las Vegas. Regarded as one of the top HR events of the year, SuccessConnect brings industry <strong>thought leaders</strong>, current and prospective <strong>customers</strong>, <strong>technology partners</strong>, and <strong>solutions experts</strong> together to share their <strong>experiences</strong>, <strong>best practices</strong>, and <strong>innovations</strong>. The event offers more than 100 breakout sessions alongside many <strong>high-level networking opportunities</strong>.</p> <p class="xmsonormal">The future workplace looks very different from what we see today. From technological advancements to the ever-changing nature of jobs, skills, and careers, businesses need to find ways to succeed in a world that&rsquo;s being reshaped by continuous innovation and disruption.&nbsp;Learn how SAP SuccessFactors solutions can help your company right now and help <strong>plan for future initiatives</strong>.</p> <hr> <p></p> <table class="template-2col image-l split50 mceNonEditable" style="width: 100%;" border="0" cellspacing="0" cellpadding="0"> <tbody> <tr> <td class="hide-email mceEditable" style="vertical-align: top; font: 14px/21px Arial, Helvetica, sans-serif; color: #444444;" valign="top" width="50%"> <p><img class="photo" src="https://portal.thinkwgroup.com/html-email/sap/email/images/image-lasvegas.jpg" width="280" height="158" /></p> </td> <td class="mobile-block2 mceEditable" style="vertical-align: top; font: 14px/21px Arial, Helvetica, sans-serif; color: #444444;" width="50%"> <p>This event provides a fantastic forum to meet other HR professionals and find out how they&rsquo;re using SAP SuccessFactors to help <strong>drive a digital HR strategy</strong>, transform talent, recruitment, and learning programs, as well as <strong>improve HR process efficiency</strong>.</p> </td> </tr> <tr> <td colspan="2" valign="middle" height="10">&nbsp;</td> </tr> </tbody> </table> <p class="xmsonormal">Enjoy a celebratory evening at KAOS nightclub in the iconic Palms Resort Casino, where you&rsquo;ll get to network with your peers while enjoying great entertainment.</p> <p><a href="https://events.sap.com/successconnect/en/las-vegas-2019" target="_blank" data-sap-hpa-ceimo-ioi-link="73555000100800000774"><strong>Please register here.</strong></a></p> <p>We look forward to seeing you in Las Vegas!</p> <table class="mceNonEditable" border="0" width="100%" cellspacing="0" cellpadding="0"> <tbody> <tr data-section="callout"> <td> <table width="100%" cellspacing="0" cellpadding="0" bgcolor="#f5f5f5"> <tbody> <tr> <td style="line-height: 1px; font-size: 1px;" height="16">&nbsp;</td> </tr> <tr> <td> <table width="100%" cellspacing="0" cellpadding="0"> <tbody> <tr> <td class="width20 " width="42">&nbsp;</td> <td class="mceEditable" style="font: 14px/21px Arial, Helvetica, sans-serif; color: #444444;"> <p><strong>SAP SuccessFactors SuccessConnect</strong></p> <p><strong>Date:</strong><br />September 16&ndash;18, 2019</p> <p><strong>Location:</strong><br />Aria Resort and Casino</p> <p><strong>Address:</strong><br />3730 S Las Vegas Blvd<br />Las Vegas, NV 89158</p> <table class="cta-button mceNonEditable" border="0" cellspacing="0" cellpadding="0"> <tbody> <tr> <td class="widthAuto mceEditable" style="border-radius: 5px;" align="center" valign="middle" bgcolor="#008fd3" width="250" height="40"><a class="font14" style="font: 18px/18px Arial, Helvetica, sans-serif; color: #ffffff; text-align: center; text-decoration: none; display: block;" href="https://events.sap.com/successconnect/en/las-vegas-2019" target="_blank" data-sap-hpa-ceimo-ioi-link="73555000100800000773">Register today &rsaquo;</a></td> </tr> <tr> <td style="line-height: 1px; font-size: 1px;" height="15">&nbsp;</td> </tr> </tbody> </table> </td> <td class="width20 " width="42">&nbsp;</td> </tr> </tbody> </table> </td> </tr> <tr> <td style="line-height: 1px; font-size: 1px;" height="16">&nbsp;</td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </table> </td> </tr> <tr> <td height="35" class="height28" style="line-height:1px; font-size:1px;">&nbsp;</td> </tr> </table> </td> </tr> </table> </td> </tr> <tr> <td> <div style="display:none; white-space:nowrap; font:15px/2px courier; color:#ffffff;">- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -</div> </td> </tr> </table> </td> </tr> </table> </body> </html>函数。

示例:

combineLatest()