As a newcomer to stackoverflow and not a native English speaker, I apologize for any errors in advance.
I am currently working on an Angular/C# project for a course, and I need an Angular mat-select
that functions with an ID (number) but displays a String instead.
In my TypeScript class, I already have an Array<number> fruitIDs
. My objective is to iterate over each element of the array and apply the function fruitName(fruitID)
on it (which returns a string).
The challenge I'm facing is figuring out how to structure the elements of the array along with their corresponding function values in a format like:
fruits =
[{value: idOfFirstFruit, viewValue: fruitName(idOfFirstFruit)},
{value: idOfSecondFruit, viewValue: fruitName(idOfSecondFruit)},....]
If I can have an object in this format, then my mat-select
can access and store the `value` while displaying 'fruitName(value)' instead.
Any help would be greatly appreciated. Thank you in advance!