Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create og-currency directive #169

Open
scottohara opened this issue Oct 14, 2019 · 1 comment
Open

Create og-currency directive #169

scottohara opened this issue Oct 14, 2019 · 1 comment

Comments

@scottohara
Copy link
Owner

(Not to be confused with og-input-currency, which is an input field that accepts/displays currency values).

In a number of views (e.g. 3 x instances in the accounts index alone), we display currency values using markup similar to the following:

<td class="amount" ng-class="::{'text-danger': amount < 0}">{{::amount | currency}}</td>

The outer tag can differ (e.g. <td> vs <th>), and the model value can differ (e.g. account.closing_balance vs accountType.total vs vm.netWorth), but there is some commonality repeated each time:

  • General styling (class="amount")
  • Conditional styling of negative amounts (ng-class="::{'text-danger': x < 0}")
  • Use of angular's currency filter ({{::x | currency}})

We should consider creating a directive that encapsulates these common traits of currency display to simplify the markup and remove the duplication.

e.g.

<th og-currency="vm.netWorth">Total: </th>

The directive would apply the general & conditional currency styles to the outer tag; and append {{:: x | currency}} to the element's text content (where x is the value passed as the directive attribute).

@scottohara
Copy link
Owner Author

Sometimes we have $0.00 amounts with the text-danger class being applied, because the underlying value is actually -0 (negative zero).

The ng-class expression should be ng-class="::{'text-danger': x < -0}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant