Apologies for this probably super confusing title, I don't know if its exactly accurate with what I am trying to do.
I have a component that is assigning objects of data to variables so that they can be typecast. I have interfaces created for this purpose:
export interface Role {
RoleID: number;
RoleName: string;
}
export interface Language {
LanguageID: number;
LanguageName: string;
}
...
roles: Role[] = [];
languages: Language[] = [];
I am using an npm module called ng-select which adds some extended functionality to select inputs.
My HTML is set up like so:
<ng-select
[allowClear]="true"
[items]="roles"
placeholder="No role selected">
</ng-select>
All of my select inputs use an ID (value) and Label (text). This is great because the module allows for that.
Array of items from which to select. Should be an array of objects with id and text properties.
My question is as follows: The object that this module is wanting is needed the property names to be id and text. Since I am typing my inputs to the interface though, I am unable to rename them in there.
Are there any suggestions on how I can map this data in a way where I can provide the module my object and say that RoleID = id and RoleName = text for example.
In short, my current object of:
{
RoleID: 123,
RoleName: 'Admin'
}
Needs to be:
{
id: 123,
text: 'Admin'
}