How can I access the angular2 Http service before calling bootstrap ()?

I need to find out if the user is authenticated or not, when the root component is loaded, it redirects the user to /signinor loads any requested page. (I plan to do this by entering a service with a boolean if it needs to sign before making any requests).

Angular Documents mention "Platform Injector" or "Root Injector." Can I access it to get an Http object? or is it created when the bootstrap is called, and I need to create my own injector from scratch to get Http?

+4
source share
1 answer

Before downloading, the http module is not registered as a valid provider, so you cannot use the DI to create it.

Perhaps you can find a way to create it manually by importing Http and making

var http = new Http(..)

but you will have to satisfy the input arguments, and I'm not sure if he recommended trying to work with the modules before the application is in a stable boot state.

To keep this simple recommendation of mine, you need to do a pre angular check using another simple HTTP implementation like jquery etc.

+1
source

Source: https://habr.com/ru/post/1623187/


All Articles