Showing posts with label Dynamically inject services in Angular 2. Show all posts
Showing posts with label Dynamically inject services in Angular 2. Show all posts

Acquire services dynamically (or generically) in Angular 2+

Acquiring a service dynamically through injector in Angular 2(+) is pretty straightforward. All you have to do is inject the Injector itself into the component's constructor instead of the services and then get the service instance by using the injector.get() method.