简体   繁体   English

如何让异步 pipe 与 rxjs 一起使用

[英]how to get the async pipe working with rxjs

I need help, since the else loading of my async pipe does not trigger, even though the data load works correctly, the loading template never triggers when subscribing, I have a BehaviorSubject in my service.我需要帮助,因为我的异步 pipe 的 else 加载不会触发,即使数据加载正常,加载模板在订阅时也不会触发,我的服务中有一个 BehaviorSubject。 If anyone help me with any solution I would appreciate it too much as I have tried a lot of things and could not reach the expected result.如果有人帮助我解决任何问题,我将不胜感激,因为我尝试了很多事情但无法达到预期的结果。 My expected result is that when choosing a date, it triggers the subscription and while it subscribes the loading is triggered, if the length is greater than 0 the table is loaded, if not, it shows the template that there are no items.我的预期结果是,在选择日期时,它会触发订阅,并且在订阅时触发加载,如果长度大于 0,则加载表,如果不是,则显示模板没有项目。 Thank you very much in advance.非常感谢您提前。 在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

BehaviourSubject() is an observable, so you will need to subscribe to your data source before setting your subject to the result of your observable. BehaviourSubject() 是一个 observable,因此您需要先订阅您的数据源,然后再将您的主题设置为 observable 的结果。 Without a subscription there will be no result!没有订阅就没有结果!

Try the following in your test (if list is an observable in your api service):在您的测试中尝试以下操作(如果列表在您的 api 服务中是可观察的):

this.apiAgenda().list.subscribe(res => 
{
  this.list$.next(res); 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM