I'm not sure is it question related to Angular 2 or more to Typescript itself. But anyway, I have a component which emits object
<grid" (gridButtonClickEvent)="gridEvent($event)"></grid>
Here is how I catching the event
private gridEvent(event) {
console.log(event);
}
Here is the the event format of what I'm getting.
{Key: value}
So basically it's a simple object.
I want to call a function with name Key and pass a value as an argument, how is it possible? The object Key would be different, but I know all possible variants and already registered function in my component.
private Key() {}
I was trying something like this
private gridEvent(event) {
let eventName = Object.keys(event)[0];
window[eventName]();
}
But it says
window[eventName] is not a function
window? 2. Why would you do things like that? Isn't that simpler to just pass a function as an object property?