Kiara Grouwstra
Kiara Grouwstra

Reputation: 5933

use NgModule outside of Angular?

It struck me that Angular's HTTP module contains very little specific to Angular. In fact, one would be inclined to think it is rather just an RxJS Observable based HTTP toolkit that just so happened to be part of Angular, and is therefore packaged in an NgModule.

I believe the idea of Observable-based HTTP requests could make sense in other frameworks as well, and as such it could be useful to import and use @angular/http in non-Angular projects. However, this raises the question how to use an NgModule outside of Angular, notably in relation to dependency injection and class instantiation, which would otherwise be taken care of internally.

NgModule has its share of documentation on use within Angular, as it was intended. However, I can't actually seem to find any particular documentation specifically about using any of this outside of the Angular context. Has anyone here managed to use parts of Angular outside of it before?

Upvotes: 1

Views: 114

Answers (1)

Jason Aden
Jason Aden

Reputation: 2823

You're correct that the HTTP modules doesn't contain much that's specific to Angular. While it might be a good idea to break it out at some point, we haven't done the work to make that happen and currently it's not on the roadmap.

In terms of dependency injection, it could theoretically be used outside Angular, however it's largely tied up with NgModule right now so pulling the two pieces apart is non-trivial. In the future Angular will rely much less (or not at all) on reflection for dependency injection (as we get closer and closer to ahead-of-time compilation being the default), so NgModule can go away.

There may be some pieces of Angular that are broken out into separate, independent libraries. Animations is on the road map, and HTTP could be one to consider down the road as well. I think if more people were looking for these features to be available outside Angular, it would help the team to prioritize this work higher.

Upvotes: 1

Related Questions