My component is currently subscribed to data from a service, which returns a BehaviorSubject that I can subscribe to. The data object retrieved contains multiple arrays representing the Label/Value pairs for my dropdowns.
I am attempting to type cast each array into its own interface and then utilize them in my UI.
Component:
// Component code here
Interface:
// Interface code here
Service:
// Service code here
Data Object:
This:
// Data object logging here
Returns:
https://i.sstatic.net/DSUNk.png
My HTML:
// HTML code here
The Issue:
In my component, I encounter an undefined error due to the subscription not having the data when trying to assign it. I suspect there's an issue with how I'm subscribing to this data preventing me from assigning it properly. Specifically, the error indicates that 'segments' is undefined.
I aim to directly assign 'segments' from the results object because I want to be able to specify its type. Once I resolve this issue, I plan to define many more dropdowns as well.
My ultimate goal is to type out each array in the received object and give them their own interfaces. I'd like to make only one call to the service to get the data object and then individually assign it to separate objects, as I'm trying to do with 'segments.'
Several individuals have indicated that it's an async problem resulting from the subscription lacking the data at the time of assignment. I'm uncertain about how to address this within my current configuration.
I've attempted solutions like using an async pipe, ngIf, and ?. but I still encounter the undefined error.