Search code examples
javascriptangularangular5string-interpolation

String interpolation inside ngFor (click)="..."


Looping through array inside ngFor like so:

<div *ngFor="account of accounts">
    <button (click)="function1(); account.message='How do I interpolate {{account.something}} here'"
</div>

I receive error Got interpolation ({{}}) where expression was expected If I just do account.something without interpolation since it is between the single quotes it will print as literal How do I interpolate account.something


Solution

  • Just use string concatenation like:

    (click)="account.message='How do I interpolate ' + account.something + ' here'"