I created an export type shown below:
export type Program{
key: string; value: string;
}
An array of values is returned from the API like this:
apival = ["abc", "xyz" ...etc]
In my component's constructor, I am implementing the following:
program: Program[];
constructor(private service: Service){
getval = service.apival;
getval.forEach((a) => {
program.push({
key: a,
value: ""
})})}
Currently, I am trying to assign the array values as keys to the program type using a forEach loop. However, I encounter the following error:
"Cannot read property 'push' of undefined"
Note: Although I attempted to do this in the service itself and encountered the error : "Cannot Instantiate cyclic dependency"
Can anyone shed light on why this error occurs and suggest the best approach to assigning getval to programs[]. Whether it should be done in the service or component?
I prefer not to implement this logic in the OnInit() method.