@Injectable() services. In this story, we will try to solve them.
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?
We need to consume the
processData() function. In HTML file, we will create a division with
id to show the users from
dashboard.component.ts file, we will inject
Injector service in
Dashboard component’s constructor. We shall call
processData() function from
ngOnInit() by fetching
Once we have passed the
processData() function, we can start manipulating the DOM to show users.
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.
ProductService providing us mock product list.