ama*_*211 3 dynamic-function typescript angular
我在变量中有函数名称,我在按钮的单击事件上分配该变量.但它不起作用.任何帮助?
@Component({
selector: 'my-app',
template: `
<div>
<h2>Function name is: {{FunctionName}}</h2>
<input type="button" value="click here" (click) = [FunctionName]()>
</div>
<p>{{value}}</p>
`,
})
export class App {
FunctionName:string;
value: string;
constructor() {
this.FunctionName = 'clickFunction'
}
clickFunction(){
this.value = "button clicked";
}
}
Run Code Online (Sandbox Code Playgroud)
这是代码
eko*_*eko 13
语法需要像这样:
<input type="button" value="click here" (click) ="this[FunctionName]()">
Run Code Online (Sandbox Code Playgroud)
固定的plunker:https://plnkr.co/edit/xGgFQuHNH72Q9FdOPEdK ? p = preview
| 归档时间: |
|
| 查看次数: |
6777 次 |
| 最近记录: |