最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Dynamic function name in Angular 2 click event - Stack Overflow

programmeradmin9浏览0评论

While this answer is probably dead simple, I seem to be stuck. As an Angular 2 beginner, I have tried all possible binations of {}, [] and () brackets to achieve the following:

<button (click)="this.action">Click me</button>

where:

this.action = "clickMe()"

i.e. it is a string, a name of the method in that ponent that should be executed on click.

Any ideas?

While this answer is probably dead simple, I seem to be stuck. As an Angular 2 beginner, I have tried all possible binations of {}, [] and () brackets to achieve the following:

<button (click)="this.action">Click me</button>

where:

this.action = "clickMe()"

i.e. it is a string, a name of the method in that ponent that should be executed on click.

Any ideas?

Share Improve this question asked Dec 17, 2016 at 10:54 dvdbrkdvdbrk 1712 silver badges11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 21

You can use square bracket syntax like

(click)="this[action]()"

where

action="clickMe"
发布评论

评论列表(0)

  1. 暂无评论