我对角(使用AngularJs已经有很多年了)还很陌生,而且我还在和可观察到的东西做斗争:(我有这样的方法:
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;行不对。我需要它返回一个可观察的,以便我的订阅工作。有人知道怎么做吗?
发布于 2018-10-07 13:38:06
如果您不关心订阅中的返回值,则可以返回空值。这将完成可观察到的。
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);
}));https://stackoverflow.com/questions/52689003
复制相似问题