4

I need to figure out if the user is authenticated or not so when the root component is bootstrapped it will forward the user to /signin or load whatever page they requested. (I plan on doing that by injecting a service with a boolean if it needs to sign on before making any requests).

Angular's docs mention a "Platform Injector" or a "Root Injector". Can I access this to get a Http object? or is it created when bootstrap is called and I need to create my own injector from scratch to get Http?

2
  • Did you ever sort this out? Commented Jun 10, 2016 at 20:37
  • @Thibs nope I haven't Commented Jun 10, 2016 at 21:31

1 Answer 1

1

Before bootstrap the http module is not registered as a valid provider, so you can't use DI to instantiate it.

It's possible that you can find a way to instantiate it manually by importing Http and do

var http = new Http(..)

but you would have to satisfy the input arguments and I am not sure if it's recommended to try to work with modules before the application is in a stable bootstrapped state.

To keep this simple my recommendation would be to do the pre angular check using some other simple http implementation like jquery etc

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

1 Comment

I assume it's possible to create an injector yourself and pass HTTP_PROVIDERS and request Http from it.

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.