tatsu
tatsu

Reputation: 2536

Currency Pipe with dynamic arg

this :

<div *ngIf="isMonetary(col)">
  {{ row[col] | currency }}
</div>

works but is with dollar by default.

the docs (https://angular.io/api/common/CurrencyPipe) say the first arg you can pass is the currency in ISO 4217 standard

I HAVE the currency in ISO 4217 standard but it MUST be dynamic. it's not per component, or per table it's per entry in the table.

Angular's currency pipe is refusing to interpret and somehow expects args to be static :

this is read as a string and "getCurrency(row)" written out shows up on my page after the monetary value :

<div *ngIf="isMonetary(col)">
  {{ row[col] | currency:'getCurrency(row)' }}
</div>

this is an HTML syntax error :

<div *ngIf="isMonetary(col)">
  {{ row[col] | currency:'{{row['currency']}}' }}
</div>

so is this :

<div *ngIf="isMonetary(col)">
  {{ row[col] | currency:'{row['currency']}' }}
</div>

so is this :

<div *ngIf="isMonetary(col)">
  {{ row[col] | currency:{row['currency']} }}
</div>

so is this :

<div *ngIf="isMonetary(col)">
  {{ row[col] | currency:'row['currency']' }}
</div>

is there a way out of this? (no I'm not going to put a *ngIf="" for every existing currency).

Upvotes: 0

Views: 1175

Answers (3)

tatsu
tatsu

Reputation: 2536

I figured it out with pure brute force

it's :

{{ row[col] | currency:(row['currency']) }}

Upvotes: 1

xrobert35
xrobert35

Reputation: 2556

In each of your try you put the value to interpret into single quot

exemple

{{ row[col] | currency:'getCurrency(row)' }}

Simply remove those quot and angular will interpret them correctly if your method getCurrency() return an ISO 4217 string

{{ row[col] | currency:getCurrency(row)}}

Upvotes: 1

Shantanu
Shantanu

Reputation: 3513

Try this:

<div *ngIf="isMonetary(col)">
  {{ row[col] | currency:row['currency'] }}
</div>

Upvotes: 1

Related Questions