订阅功能无法正常工作 [英] subscribe function doesn't work correctly

查看:145
本文介绍了订阅功能无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这段代码中,subscribe函数在loadFromDB函数的最后一行之后执行:

in this piece of code the subscribe function executes after the last line in loadFromDB function:

  loadFromDB(){
    const loading = this.loadingCtrl.create({
      content: 'pleas wait'
    });
    loading.present();
    this.getInterviewFromDB()
      .subscribe((data) => {
        this.events = data;
        console.log( 'before');
      });
    this.getMeetingsFromDB().subscribe((data)=>{
      this.events.concat(data);
    });
    loading.dismiss();

    console.log( 'after');
  }

加载存在并在从数据库加载任何数据之前解除
,这是日志的输出

the loading is present and dismiss before loading any data from database and this is the output of the log


说明了订阅功能下的那一行在其中的console.log之后执行...可以任何机构向我解释..?!

illustrates that line under the subscribe function Execute after the console.log inside it ...can any body explain to me .. ?!

推荐答案

这非常有意义。您正在订阅异步流。你不能指望他们按顺序完成。如果你希望它们同时完成,你可以这样做:

This makes perfectly sense. You are subscribing to asynchronous steams. You cant expect them to finish in order. If you want them to finish at the same time you can do something like this:

Observable.forkJoin(this.getInterviewFromDB(), this.getMeetingsFromDB())
    .subscribe(res => {
       let interviews = res[0];
       let meetings = res[1];
    })

这篇关于订阅功能无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆