Posts

Showing posts with the label Angular DI

Angular Configuration

Image
In Previous topic we have seen about Angular Observable , in this topic we will look into configuration part of our angular application.  When an application starts it need some sort of runtime configuration information like UR endpoint etc.   APP_INITIALIZER ➤➤➤ APP_INITIALIZER is a dependency injection token that you can use to provide one or more initialization functions. The provided functions are injected at application startup and executed during app initialization. If any of these function returns a Promise or Observable, initialization does not complete until the promise is resolved or Observable is completed.  We will look into an example in which we will get some results, these results usually returned as an observable or a promise which matches exactly with the signature of APP_INITIALIZER function. So to use this service we do not need to create any new instance like Service service = new Service(); Angular will handle these through dependency injection, we ...

Services & Dependency Injection

Image
In Previous article we have learnt about Angular Forms , In this article we will look into services and dependency Injection in Angular. What is Angular Services? Angular Services are the piece of code or logic that are used to perform some specific task, A code that you can use in many components across application. Also you can say that Angular Services are objects that get instantiated only once during the lifetime of an application. Services contain methods that maintain data throughout the application. The main objective of a service is to organize and share business logic, models or data and functions will multiple component of an application. Services can be implemented though dependency injection. What are Angular Services features? Angular Services are simply typescript classes with the @ Injectable decorator. This decorator tells angular that this class is a service and it will be injected into components that need this service.  Service are used to share code across mult...