AngularJS Services and DI


  • What is and why service? 
  • Built-in (Angular provided) services 
    • $log, $location, $timeout, $interval 
  • Dependency injection (DI) 
  • Creating a custom service

What is and Why Service? 

  • Angular services are reusable objects 
    • You can use services to organize and share code across your app 
  • A service can be injected into controller, another service, filter, directive that depends on that service 
    • Angular's dependency injection subsystem ($injector) handles dependency injection 
  • Angular services are: 
    • Lazily instantiated - Angular only instantiates a service when an application component depends on it 
    • Singletons - Each component dependent on a service gets a reference to the single instance generated by the service factory


Download course content