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

What's hot (20)

PDF
Spring MVC
Aaron Schram
 
ODP
Scal`a`ngular - Scala and Angular
Knoldus Inc.
 
PPTX
Grails with swagger
NexThoughts Technologies
 
PDF
Introduction to Spring MVC
Richard Paul
 
PPTX
Auto fac mvc以及進階應用(一)
LearningTech
 
ODP
Spray - Build RESTfull services in scala
Sandeep Purohit
 
PPTX
Spring MVC Architecture Tutorial
Java Success Point
 
PDF
Spring annotation
Rajiv Srivastava
 
PPTX
Spring Web MVC
zeeshanhanif
 
PPT
Backbone js
Knoldus Inc.
 
ODP
Functional programming in Javascript
Knoldus Inc.
 
PPTX
Dependency Inversion in large-scale TypeScript applications with InversifyJS
Remo Jansen
 
PPTX
React basics
lakshaya maheshwari
 
ODP
Oro Workflows
Yevhen Shyshkin
 
PPTX
Spring jdbc
Harshit Choudhary
 
PPTX
Spring core
Harshit Choudhary
 
PPTX
Scala functions
Kunal Cholera
 
PPTX
Understanding react hooks
Maulik Shah
 
PPTX
Eclipse Day India 2015 - Java 8 Overview
Eclipse Day India
 
PDF
Spring MVC Annotations
Jordan Silva
 
Spring MVC
Aaron Schram
 
Scal`a`ngular - Scala and Angular
Knoldus Inc.
 
Grails with swagger
NexThoughts Technologies
 
Introduction to Spring MVC
Richard Paul
 
Auto fac mvc以及進階應用(一)
LearningTech
 
Spray - Build RESTfull services in scala
Sandeep Purohit
 
Spring MVC Architecture Tutorial
Java Success Point
 
Spring annotation
Rajiv Srivastava
 
Spring Web MVC
zeeshanhanif
 
Backbone js
Knoldus Inc.
 
Functional programming in Javascript
Knoldus Inc.
 
Dependency Inversion in large-scale TypeScript applications with InversifyJS
Remo Jansen
 
React basics
lakshaya maheshwari
 
Oro Workflows
Yevhen Shyshkin
 
Spring jdbc
Harshit Choudhary
 
Spring core
Harshit Choudhary
 
Scala functions
Kunal Cholera
 
Understanding react hooks
Maulik Shah
 
Eclipse Day India 2015 - Java 8 Overview
Eclipse Day India
 
Spring MVC Annotations
Jordan Silva
 

Viewers also liked (8)

PDF
[Basic HTML/CSS] 5. css - selector, units
Hyejin Oh
 
PDF
Front End Best Practices
Holger Bartel
 
PDF
Introdução a CSS
Tiago Santos
 
PDF
CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Morten Rand-Hendriksen
 
PDF
Responsive Web Design Tutorial PDF for Beginners
Bootstrap Creative
 
PPTX
Single page application 04
Ismaeel Enjreny
 
PDF
Web Design Primer Sample - HTML CSS JS
Bootstrap Creative
 
PDF
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017
Morten Rand-Hendriksen
 
[Basic HTML/CSS] 5. css - selector, units
Hyejin Oh
 
Front End Best Practices
Holger Bartel
 
Introdução a CSS
Tiago Santos
 
CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
Morten Rand-Hendriksen
 
Responsive Web Design Tutorial PDF for Beginners
Bootstrap Creative
 
Single page application 04
Ismaeel Enjreny
 
Web Design Primer Sample - HTML CSS JS
Bootstrap Creative
 
CSS Grid Changes Everything About Web Layouts: WordCamp Europe 2017
Morten Rand-Hendriksen
 
Ad

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

PDF
Dependency Injection pattern in Angular
Alexe Bogdan
 
PPTX
Angular js
Behind D Walls
 
PDF
AngularJS - Services
Nir Kaufman
 
PPTX
AngularJS: Service, factory & provider
Corley S.r.l.
 
PDF
AngularJS Best Practices
Betclic Everest Group Tech Team
 
PPTX
AngularJs-training
Pratchaya Suputsopon
 
PDF
"Angular.js Concepts in Depth" by Aleksandar Simović
JS Belgrade
 
PPTX
AngularJS $Provide Service
Eyal Vardi
 
PDF
Workshop 13: AngularJS Parte II
Visual Engineering
 
PDF
Angular js
E2 Partners
 
PDF
ngMess: AngularJS Dependency Injection
Dzmitry Ivashutsin
 
PPTX
The AngularJS way
Boyan Mihaylov
 
PPTX
Angular js for beginners
Munir Hoque
 
PPTX
Dive into Angular, part 1: Introduction
Oleksii Prohonnyi
 
PDF
AngularJS
Hiten Pratap Singh
 
ODP
AngularJs Crash Course
Keith Bloomfield
 
ODP
Angular js-crash-course
Keith Bloomfield
 
PPTX
AngularJs presentation
Phan Tuan
 
PDF
2013 - Nate Abele Wield AngularJS like a Pro
PHP Conference Argentina
 
Dependency Injection pattern in Angular
Alexe Bogdan
 
Angular js
Behind D Walls
 
AngularJS - Services
Nir Kaufman
 
AngularJS: Service, factory & provider
Corley S.r.l.
 
AngularJS Best Practices
Betclic Everest Group Tech Team
 
AngularJs-training
Pratchaya Suputsopon
 
"Angular.js Concepts in Depth" by Aleksandar Simović
JS Belgrade
 
AngularJS $Provide Service
Eyal Vardi
 
Workshop 13: AngularJS Parte II
Visual Engineering
 
Angular js
E2 Partners
 
ngMess: AngularJS Dependency Injection
Dzmitry Ivashutsin
 
The AngularJS way
Boyan Mihaylov
 
Angular js for beginners
Munir Hoque
 
Dive into Angular, part 1: Introduction
Oleksii Prohonnyi
 
AngularJs Crash Course
Keith Bloomfield
 
Angular js-crash-course
Keith Bloomfield
 
AngularJs presentation
Phan Tuan
 
2013 - Nate Abele Wield AngularJS like a Pro
PHP Conference Argentina
 
Ad

More from Sumanth krishna (12)

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

Recently uploaded (20)

PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Biography of Daniel Podor.pdf
Daniel Podor
 
Advancing WebDriver BiDi support in WebKit
Igalia
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 

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