I am new to Angular (used AngularJs for a number of years) and I am struggling with Observables :( I have this method:
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);
}));
}
The line if (!shouldFilter) return;
is not right. I need it to return an Observable so my subscriptions work.
Does anyone know how to do that?