Reputation: 223
I have the following function. When this function triggers action is being passed as an argument to this function. I want to use the action parameter to dynamically call a property.
The following is where I'm stuck.
onChange(event: any, id: number, action: any){
this.action[id]["Selected"] = true
}
If I have to manually do it, it will look something like this.
onChange(event: any, id: number, action: any){
if( action == "StatutoryReq"){
this.StatutoryReq[id]["Selected"] = true
} else if( action == "StatutoryReqErp2007"){
this.StatutoryReqErp2007[id]["Selected"] = true
}
}
Upvotes: 0
Views: 227
Reputation: 1798
In Javascript/Typescript,
obj.some_fn
is same as
obj['some_fn']
So you should be able to use this[action]
.
onChange(event: any, id: number, action: any){
this[action][id]["Selected"] = true
}
Upvotes: 2