[英]Dynamic function name in Angular 2 click event
While this answer is probably dead simple, I seem to be stuck. 虽然这个答案可能很简单,但我似乎陷入困境。 As an Angular 2 beginner, I have tried all possible combinations of {}, [] and () brackets to achieve the following: 作为Angular 2的初学者,我尝试了{},[]和()括号的所有可能组合来实现以下功能:
<button (click)="this.action">Click me</button>
where: 哪里:
this.action = "clickMe()"
ie it is a string, a name of the method in that component that should be executed on click. 即它是一个字符串,该组件中应该在点击时执行的方法的名称。
Any ideas? 有任何想法吗?
You can use square bracket syntax like 您可以使用方括号语法
(click)="this[action]()"
where 哪里
action="clickMe"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.