I have to create dynamic button from json file. My JSON is as per below:
{ button : { title : "Submit", event : "FunctionName", color : "white".... }}
My Component:
@Component({
selector: 'my-app',
template: `
<div>
<h2>Function name is: {{FunctionName}}</h2>
<input type="button" value="click here" (click)="this[FunctionName]()">
</div>
<p>{{value}}</p>
`,
})
export class App {
FunctionName:string;
value: string;
constructor() {
this.FunctionName = button.FunctionName;
}
Button.FunctionName(){ //<-----How can I give name from JSON
this.value = "button clicked";
}
}
My function name is coming from JSON file. so How can I create such function in my TS file?
Enhancement of Dynamic function calling Angular 2