I am completely new to using RxJS and any assistance offered would be greatly appreciated!
Within my component's HTML template, I am looking to create a radio button list.
The values for this list are fetched from an observable using the async pipe.
This snippet shows the template section for the radio button list:
<div *ngIf="entities$ | async as entities">
<mat-radio-group
aria-labelledby="entities-radio-group-label"
class="entities-radio-group"
<mat-radio-button *ngFor="let entity of entities" [value]="entity">
{{entity.description}}
</mat-radio-button>
</mat-radio-group>
</div>
In the component class, I have an observable that retrieves the entities' data via a service. I also apply a filter based on the entity type.
entities$: Observable<Entity[]> = this.eventsService.entities$
.pipe(
map(items => items.filter(item => item.type.toLowerCase().indexOf("set") > -1)),
)
The structure of a retrieved entities object is as follows:
[
{"id":"34534534643364",
"type":"SET",
"description":"some description",
"link":"/conf/sets/34534534643364"},
{"id":"5474745744457547",
"type":"SET",
"description":"other description",
"link":"/conf/sets/5474745744457547"}
]
While the current setup successfully filters and displays "SET" type entities, I need to implement additional filtering based on information obtained from an API call using the entity link.
A sample request to the API initiated by the service looks like this:
restService.call<any>(entityUrl)
.pipe(finalize(()=>this.loading=false))
.subscribe(
apidata => console.log(`data: ${JSON.stringify(apidata)}`),
error => this.alert.error('Failed to retrieve entity: ' + error.message)
);
The response received is an object structured as shown below:
{
"id": "34534534643364",
"name": "some name",
"description": null,
"type": {
"value": "LOGICAL",
"desc": "Logical"
},
"content": {
"value": "IEP",
"desc": "This it the value I need"
},
"status": {
"value": "ACTIVE",
"desc": "Active"
}
}
To conduct additional filtering, specifically utilizing the value under "desc", I attempted adding a function to the source observable but encountered issues due to the asynchronous nature of the API request processing.
An alternative approach I considered was working only with the results from the API for populating the template's radio button group. I managed to create an array of observables representing each API result but am uncertain about incorporating this array into the template.
Any guidance or suggestions provided will be highly valued!