In Angular2 I have multiple buttons and on click they set a value. Is it possible to use expression in the click event ie., instead of calling a function can we set the value directly?
<button (click)="setValue(1)">1</button>
<button (click)="setValue(1)">2</button>
<button (click)="setValue(1)">3</button>
to some thing like
<button (click)="{{value=1}}">1</button>
<button (click)="{{value=1}}">2</button>
<button (click)="{{value=1}}">3</button>
You can use expressions but don't use {{}}
<button (click)="value=1">1</button>
Angular evaluates the value part when the attribute name is wrapped in [], () (or both [()] or when the value contains {{}}. Don't use [] and () together with {{}}.
{{}} stringifies the result. If you want to bind non-string values to properties don't use {{}} at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With