How to Inject Angular Services in External JavaScript Functions, and Component’s Static Functions

Consuming Angular Service in External JavaScript function

Let’s take a processData() function outside your Angular component. This function does some task by consuming Angular service. Since this function is not part of Angular, how will you pass the instance created by Angular Dependency Injection (DI), to this function?

Consuming Service from component’s “Static” method

Another scenario where we want to pass service to a component’s static function and show data in HTML.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store