What is a Dependency Injection?
Dependency Injection gives us the ability to add functionalities across different components at runtime in an angular application.
We can create a service by importing Injectable library from our @angular/core.
import {
Injectable
} from '@angular/core';
@Injectable ()
export class Service {
commonFunction(): string {
return "Hello world";
}
}
In angular application we need to give references inside the provider.
Provider in angular is a pre-defined object that gives instructions to the injector in our application on how to create those dependencies.
Most dependencies are services in angular hence angular uses DI to provide components the individual services they need for functionality.
0 comments:
Post a Comment