Issue
I have below Observable
config$: Observable<QueryBuilderConfig>;
this.config$.pipe(map(item => {
return {
fieldGroups: [
{ id: CustomAttributeEntityType.Risk, label: this.l('Risk') },
{ id: CustomAttributeEntityType.RiskAssessment, label: this.l('Risk Assessment') }
],
fields: this.metricCreateConfigureStore.queryBuilderFields$, // Get the value from obserable
allowEmptyRules: true,
allowEmptyRulesets: false
}
}));
In the field
attribute, I want to get the value from another observable, something like below
fields: this.metricCreateConfigureStore.queryBuilderFields$
queryBuilderFields$
return Observable
as below
readonly queryBuilderFields$: Observable<{ [key: string]: QueryBuilderFieldsDto }> = this.select(state => state.queryBuilderFields);
How can I get the value, without subscribe over there??
Solution
Depends on what you exactly mean by "value from other observable": two streams emitting independently, and you want to catch values from both? That's
combineLatest([stream1$, stream2$])
.subscribe(([val1$, val2$]) => //...
Or use value from one stream to create another one? That's switchMap
(or maybe one of its siblings, like concatMap
, mergeMap
etc.):
stream1$.pipe(
tap(/* maybe some side effects here */),
switchMap(value1 => generateStream2(value1))
).subscribe(value2 => //...
Answered By - mbojko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.