Попробуй так:
{ button : { title : "Submit", event : () => this.FunctionName(), color : "white".... }}
Если вы не можете изменить json, это может сработать:
HTML:
<input type="button" value="click here" (click)="callFunction(FunctionName)">
TS:
callFunction(functionName:string) {
let comp_obj = new ClassComponent();
comp_obj[functionName]();
}
Из stackbiltz: Добавьте это в TS
callFunction(FunctionName: string) {
let x = new AppComponent();
x[FunctionName]();
}
enrollmentFormProblem() {
alert("enrollmentFormProblem called")
}
HTML:
<button (click)="callFunction(dynamicButton[0].event)">{{this.dynamicButton[0].description}}</button>
Чтобы добавить функцию динамически, предварительно определив ее, сделайте следующее:
callFunction(FunctionName: string) {
let x = new AppComponent();
x[FunctionName] = new Function (
console.log(`${FunctionName} created`)
)
}