SlideShare a Scribd company logo
AngularJS
MODULES – SERVICES – FACTORY - PROVIDERS
Request flow in AngularJS
Module
Routes
Config
ControllerView
Directives
$scope
Factory
Service
Provider
Value
Modules
Module
Routes
Config Filter Directive ControllerFactory
Service
Provider
Value
Modules
 Are logical containers of various parts of application
 Includes controllers, services, filters, directives, values, constants… as shown
 Unlike in many languages, here Modules are not namespace
 Definition
 Module is a container for application controllers
Module - container
Controller 1
Controller 2
Directive 5
Directive 7
Module 1
Controller 3
Controller 4
Directive 6
Directive 8
Module 2
Module 1
Module 2
Controller 3
Controller 4
Directive 6
Directive 8
Controller 1
Controller 2
Directive 5
Directive 7
Injector
Controllers
 As the name suggest… the controllers are to control the request flow
 should be very thin devoid of any business logic, persistent data
 Use to set up the initial state of $scope object
 Add more behaviour to $scope object
 Not to use for
 DOM manipulations (make use of directives, databinding)
 Format input (make use of form controls)
 Filter output (make use of filters)
 Sharing code/state across controllers (make use of angular services)
 Managing the life-cycle of other components
Provider
 A provider is the most configurable and verbose version of services because it's based
on prior settings or logic.
 Syntactically defined as a custom type that implements $get method
 As you might have guessed, a provider can be injected into module's config() block,
where a user can configure it before the app starts.
 Should use, if to expose an API for application-wide configuration that must be made
before the application starts.
 This is usually interesting only for reusable services whose behaviour might need to
vary slightly between applications.

Services
 provides us method to keep data across the lifetime of the angular app
 provides us method to communicate data across the controllers in a consistent
way
 is a singleton object and it gets instantiated only once per application
 is used to organize and share data and functions across the application
 are instantiated lazily, means they are invoked only when they are triggered
Services
 A service is registered using the service() function of angular.module().
 The second argument to service() is a constructor function. When we ask for the
service as a dependency, AngularJS creates an object from this constructor
function and injects it.
 A service is a singleton. AngularJS instantiates the service object only once and all
other components share the same instance.
Factory
 A factory is another injectable type and effectively same as Service
 It’s a factory of Service, able to determine what to instantiate and what to return
 You register a factory by calling the factory() function on angular.module().
Compare
Features / Recipe type Factory Service Value Constant Provider
can have dependencies yes yes no no yes
uses type friendly injection no yes yes yes no
object available in config
phase
no no no yes yes
can create functions yes yes yes yes yes
can create primitives yes no yes yes yes
Demo
 http://jsfiddle.net/sumanthkrishna/6dwmuL8n/1/
 http://jsfiddle.net/sumanthkrishna/rkLdrcg0/2/
 http://jsfiddle.net/sumanthkrishna/aq1k6cx2/1/
References
 https://docs.angularjs.org/guide/providers
 http://tylermcginnis.com/angularjs-factory-vs-service-vs-provider/

More Related Content

DOCX
Ruby Interview Questions
PPTX
Angular 2
PPTX
Spring from a to Z
PPTX
Angular Presentation
PPTX
React hooks
PDF
Introduction to React Hooks
PPTX
Flask & Flask-restx
PPTX
Mule java part-4
Ruby Interview Questions
Angular 2
Spring from a to Z
Angular Presentation
React hooks
Introduction to React Hooks
Flask & Flask-restx
Mule java part-4

What's hot (20)

PDF
Spring MVC
ODP
Scal`a`ngular - Scala and Angular
PPTX
Grails with swagger
PDF
Introduction to Spring MVC
PPTX
Auto fac mvc以及進階應用(一)
ODP
Spray - Build RESTfull services in scala
PPTX
Spring MVC Architecture Tutorial
PDF
Spring annotation
PPTX
Spring Web MVC
PPT
Backbone js
ODP
Functional programming in Javascript
PPTX
Dependency Inversion in large-scale TypeScript applications with InversifyJS
PPTX
React basics
ODP
Oro Workflows
PPTX
Spring jdbc
PPTX
Spring core
PPTX
Scala functions
PPTX
Understanding react hooks
PPTX
Eclipse Day India 2015 - Java 8 Overview
PDF
Spring MVC Annotations
Spring MVC
Scal`a`ngular - Scala and Angular
Grails with swagger
Introduction to Spring MVC
Auto fac mvc以及進階應用(一)
Spray - Build RESTfull services in scala
Spring MVC Architecture Tutorial
Spring annotation
Spring Web MVC
Backbone js
Functional programming in Javascript
Dependency Inversion in large-scale TypeScript applications with InversifyJS
React basics
Oro Workflows
Spring jdbc
Spring core
Scala functions
Understanding react hooks
Eclipse Day India 2015 - Java 8 Overview
Spring MVC Annotations
Ad

Viewers also liked (8)

PDF
[Basic HTML/CSS] 5. css - selector, units
PDF
Front End Best Practices
PDF
Introdução a CSS
PDF
CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
PDF
Responsive Web Design Tutorial PDF for Beginners
PPTX
Single page application 04
PDF
Web Design Primer Sample - HTML CSS JS
PDF
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017
[Basic HTML/CSS] 5. css - selector, units
Front End Best Practices
Introdução a CSS
CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Responsive Web Design Tutorial PDF for Beginners
Single page application 04
Web Design Primer Sample - HTML CSS JS
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017
Ad

Similar to Services Factory Provider Value Constant - AngularJS (20)

PPT
17612235.ppt
PDF
AngularJS in practice
PPTX
Intoduction to Angularjs
PPTX
Angular interview questions
PPTX
Angular 9
PPTX
Angular 18 course for begineers and experienced
PDF
AngularJS Best Practices
PDF
AngularJS: Overview & Key Features
PPTX
Building a website with angular 2
PPTX
Building a website with angular
PDF
Building blocks of Angular
PPTX
Dive into Angular, part 1: Introduction
PPTX
Angular crash course
PDF
Angular2 with type script
PPTX
mobile development using node js and java
PPTX
Understanding angular js
PDF
Dependency Injection pattern in Angular
PPT
Ch19
ODP
Angular2
17612235.ppt
AngularJS in practice
Intoduction to Angularjs
Angular interview questions
Angular 9
Angular 18 course for begineers and experienced
AngularJS Best Practices
AngularJS: Overview & Key Features
Building a website with angular 2
Building a website with angular
Building blocks of Angular
Dive into Angular, part 1: Introduction
Angular crash course
Angular2 with type script
mobile development using node js and java
Understanding angular js
Dependency Injection pattern in Angular
Ch19
Angular2

More from Sumanth krishna (12)

PPTX
Scope demystified - AngularJS
PPT
Jasmine - A BDD test framework for JavaScript
PPT
Ruby on Rails industry trends
PDF
Introducing Ruby/MVC/RoR
PPT
Watir Presentation Sumanth Krishna. A
PPS
Life Pencil And U
PDF
Ro R Based Social Networking Apps Compared
PPS
Put The Glass Down
PPS
New Rabbit Tortoise Story
PPT
RoR relevance to startups Session @ Barcamp5 - Sumanth Krishna
PDF
Cookie - story
PPT
How Brain Works against in identifying colors?
Scope demystified - AngularJS
Jasmine - A BDD test framework for JavaScript
Ruby on Rails industry trends
Introducing Ruby/MVC/RoR
Watir Presentation Sumanth Krishna. A
Life Pencil And U
Ro R Based Social Networking Apps Compared
Put The Glass Down
New Rabbit Tortoise Story
RoR relevance to startups Session @ Barcamp5 - Sumanth Krishna
Cookie - story
How Brain Works against in identifying colors?

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PPTX
Cloud computing and distributed systems.
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
Advanced IT Governance
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Reimagining Insurance: Connected Data for Confident Decisions.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Advanced Soft Computing BINUS July 2025.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
KodekX | Application Modernization Development
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
GamePlan Trading System Review: Professional Trader's Honest Take
Cloud computing and distributed systems.
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Advanced IT Governance
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Reimagining Insurance: Connected Data for Confident Decisions.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
NewMind AI Monthly Chronicles - July 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
Review of recent advances in non-invasive hemoglobin estimation
Chapter 3 Spatial Domain Image Processing.pdf
Advanced Soft Computing BINUS July 2025.pdf
MYSQL Presentation for SQL database connectivity
KodekX | Application Modernization Development
Dropbox Q2 2025 Financial Results & Investor Presentation
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf

Services Factory Provider Value Constant - AngularJS

  • 1. AngularJS MODULES – SERVICES – FACTORY - PROVIDERS
  • 2. Request flow in AngularJS Module Routes Config ControllerView Directives $scope Factory Service Provider Value
  • 3. Modules Module Routes Config Filter Directive ControllerFactory Service Provider Value
  • 4. Modules  Are logical containers of various parts of application  Includes controllers, services, filters, directives, values, constants… as shown  Unlike in many languages, here Modules are not namespace  Definition  Module is a container for application controllers
  • 5. Module - container Controller 1 Controller 2 Directive 5 Directive 7 Module 1 Controller 3 Controller 4 Directive 6 Directive 8 Module 2 Module 1 Module 2 Controller 3 Controller 4 Directive 6 Directive 8 Controller 1 Controller 2 Directive 5 Directive 7 Injector
  • 6. Controllers  As the name suggest… the controllers are to control the request flow  should be very thin devoid of any business logic, persistent data  Use to set up the initial state of $scope object  Add more behaviour to $scope object  Not to use for  DOM manipulations (make use of directives, databinding)  Format input (make use of form controls)  Filter output (make use of filters)  Sharing code/state across controllers (make use of angular services)  Managing the life-cycle of other components
  • 7. Provider  A provider is the most configurable and verbose version of services because it's based on prior settings or logic.  Syntactically defined as a custom type that implements $get method  As you might have guessed, a provider can be injected into module's config() block, where a user can configure it before the app starts.  Should use, if to expose an API for application-wide configuration that must be made before the application starts.  This is usually interesting only for reusable services whose behaviour might need to vary slightly between applications. 
  • 8. Services  provides us method to keep data across the lifetime of the angular app  provides us method to communicate data across the controllers in a consistent way  is a singleton object and it gets instantiated only once per application  is used to organize and share data and functions across the application  are instantiated lazily, means they are invoked only when they are triggered
  • 9. Services  A service is registered using the service() function of angular.module().  The second argument to service() is a constructor function. When we ask for the service as a dependency, AngularJS creates an object from this constructor function and injects it.  A service is a singleton. AngularJS instantiates the service object only once and all other components share the same instance.
  • 10. Factory  A factory is another injectable type and effectively same as Service  It’s a factory of Service, able to determine what to instantiate and what to return  You register a factory by calling the factory() function on angular.module().
  • 11. Compare Features / Recipe type Factory Service Value Constant Provider can have dependencies yes yes no no yes uses type friendly injection no yes yes yes no object available in config phase no no no yes yes can create functions yes yes yes yes yes can create primitives yes no yes yes yes