Understanding Dependency Injection

Dependency Injection in AngularJS can be defines as the software design pattern which defines the way the software components are dependent on each other. AngularJS provides a set of components that can be injected in the form of dependencies such as factory, value, constant, service, and provider.

factory

value

constant

service

provider

1. factory – It is a function which returns value. It produces value on demand when a service or controller needed.2. value – It is a javascript object It passes values to controller config phase.3. constant – constants passes values at config phase considering the fact that value cannot be used to be passed during config phase.5. service – It is a singleton javascript object which have a set of functions to execute certain tasks. It is defined by service() function.6. provider – It is used to create factory, service etc. in config phase.e.g.