-1

I want to set currency all across the angular app. I have used currency pipe but have to call api for currency every-time in the component. But I want to set currency at once and used it across the whole application.

Currently i am using 123 | currency : 'INR'.

Is there any alternate solution apart from creating a custom pipe? Or should i modify currency pipe if possible.

2 Answers2

0

You should not perform API calls in your pipes. This will lead to many, many API calls being performed. What you should do is create a service, which will hold the value of the currency you want to query for. This service can be injected in your pipe and can provide the value if already fetched.

Fabian Strathaus
  • 3,192
  • 1
  • 4
  • 26
-3

The only solution i am seeing from here is that i have to create a new custom pipe for currency then call an api in pipe itself and use it across the application.

  • You should not do that without implementing some kind of fetching mechanism. Nevertheless this would still result in API calls for every usage of this pipe. – Fabian Strathaus Sep 23 '22 at 12:40
  • I know how pipe works in angular. I was planning to hold currency in a service only. But thanks for the negative reputation. – Aditya Adhikari Sep 23 '22 at 12:45
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 28 '22 at 18:01