2

Hi I try to add dynamic functions name on button but don't know how to do that try something but doesn't work.

My example

<button md-icon-button (click)="on{{scial.name}}()"><i class="{{social.icon}} "></i></button>

it's on *ngFor

Is it realy to do?

1
  • In general {{}} is not supposed to be used together with [input] or (event). If you use [] or () then use x + 'y' to concatenate strings in the expression. Commented Feb 22, 2017 at 16:38

1 Answer 1

3

You need to use this explicitly

<button md-icon-button (click)="this['on' + scial.name]()">
Sign up to request clarification or add additional context in comments.

5 Comments

it works but give error EXCEPTION: Error in ./SignUpSocialItem class SignUpSocialItem - inline template:3:4 caused by: self.context.self[("on" + self.context.social.name)] is not a function
Seems to work without problems for me plnkr.co/edit/zENP2iTnlIzwRJqXjvuf?p=preview
You're welcome :) Glad to hear you could make it work.
Really, I always thought this is not supported in bindings. Only on the phone right now and can't test. Will have a look later.
Just tried it. this['on' + 'Foo']() really works as well. Thanks a lot for the hint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.