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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
You can set an observable to call your service whenever there's a change in rates. So it's handled automatically

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.