Is there a way to retrieve the value of an object in Angular using a variable as the member identifier?
For example:
--> my Angular class object:
Object1 {
name: foo
property2: bar
}
--> my function:
myFunction(memberName: string)
{
return Object1.membername
}
--> when executing: myFunction("name") returns "foo"
Is this achievable?
Additional info:
This is the object class:
import { headerStateColor } from "../header/headerDeviceStateColor.model";
import { betterNameForDeviceState } from "./deviceStateHelper";
export class deviceModel {
// Class properties here...
};
This is the class where I need to utilize the "dynamic member"
export class DeviceDetailsComponent implements OnInit {
// Class methods and variables defined here...
}
An error occurs when attempting to use a variable as an identifier:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'deviceModel'.
No index signature with a parameter of type 'string' was found on type 'deviceModel'.ts(7053)