首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角6返回可观测

角6返回可观测
EN

Stack Overflow用户
提问于 2018-10-07 13:33:34
回答 1查看 2.7K关注 0票数 0

我对角(使用AngularJs已经有很多年了)还很陌生,而且我还在和可观察到的东西做斗争:(我有这样的方法:

代码语言:javascript
复制
filterProducts(categoryId: string, questions: Question[], organisationId: string): Observable<any> {
  var formulas = this.formulaService.getFromSelectedAnswers(questions);
  let shouldFilter = this.shouldFilterProducts(categoryId, questions, formulas);
  if (!shouldFilter) return;

  return this.filterOrScore(categoryId, organisationId, formulas).pipe(map(products => {
    if (!products || !products.length) return;

    this.products.length = 0;
    this.products.push.apply(this.products, products);
    this.questionService.filterQuestionsByProducts(products, questions);      
    this.questionService.updateSession(questions);
  }));
}

if (!shouldFilter) return;行不对。我需要它返回一个可观察的,以便我的订阅工作。有人知道怎么做吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-07 13:38:06

如果您不关心订阅中的返回值,则可以返回空值。这将完成可观察到的。

代码语言:javascript
复制
import {empty} from 'rxjs';

filterProducts(categoryId: string, questions: Question[], organisationId: string): Observable<any> {
  var formulas = this.formulaService.getFromSelectedAnswers(questions);
  let shouldFilter = this.shouldFilterProducts(categoryId, questions, formulas);
  if (!shouldFilter) return empty();

  return this.filterOrScore(categoryId, organisationId, formulas).pipe(map(products => {
    if (!products || !products.length) return empty();

    this.products.length = 0;
    this.products.push.apply(this.products, products);
    this.questionService.filterQuestionsByProducts(products, questions);      
    this.questionService.updateSession(questions);
  }));
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52689003

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档