0

I am developing shop which suppots many different currency. On backend all money are in USD, curreny will be converted at client side while displaying page basing on user IP.

Im wondering if I should use:

  1. Service which will use $http call to gather current currency rate from for example google page and after all items are displayed, loaded then start converting all prices to already set user default currency, it shouldn't take long.
  2. Custom angularJS filter but it can't call currency request every time the info about currency must be gathered before filter start working. So anyway I have to create and execute some function, ( service or factory ) and constrain to execute this service before filter start his job. But basing on this answer service execute before filter.

Which of this approach is better? Or maybe there is some better way of converting currency on client side that I don't know?

BT101
  • 3,666
  • 10
  • 41
  • 90

1 Answers1

1

creating a custom filter is better, but not as dynamic. So unless you could then create a separate $http service which could get your rates from google or wherever, then pass it into your filter. So basically, your filter calls a service which gives it its variables for conversion.

tobie
  • 187
  • 10
  • Yes but service have to be execute only once right? And the response of `$http` call must be stored in for example `$rootScope` or `$localForage` which I am actually using in this project but I don't know which would be faster I would eventually do some testing on it. – BT101 Oct 14 '17 at 23:16
  • You can set an observable to call your service whenever there's a change in rates. So it's handled automatically – tobie Oct 15 '17 at 10:08