Using angular HttpClient in a typescript singleton class

Hello there !

I am new to Ionic/Angular and web development in general so excuse me if my question sounds stupid.

I am making an app in which users can log in and I am doing some refactoring right now. One thing I’m trying to achieve is to have a UserAccount class that has a singleton so I can access it anywhere in the app. This class contains the login function which is making an http request. To do so I wanted to use the httpClient module from angular but I realised I cannot just use http = new HttpClient(); because it takes a httpHandler as a parameter.
So the question that came to my mind is the following :
how is angular calling the constructors of my pages when I have this for example :
constructor (private http : HttpClient){};
Where is he calling that constructor and what does it give as parameter ?

Don’t attempt to create singletons yourself. Let Angular DI manage lifecycle.

1 Like

Hey, thanks for answering. Indeed I should have looked deeper in the doc !