Services

Crazy Bugs

  • Services are same as that of Factory and can be used as alternatives to each others
  • Main difference is that in Services whole function acts as object whereas in Factory it returns object
  • Services relies on this keyword

Process to create Service

Create custom module

app.js

appFact

Create custom Service

  • Create anonymous function
  • Create variable which stores data
  • create function getCustomers which is going to returns all customers
  • At last, service object should be registered with module

CustomerService.js

custSer

Inject service into controller

  • Take parameters as $scope and to inject service as customerService
  • Create a function and call customerService‚Äôs function to get customers
  • Register controller with module

CustomerController.js

custControSer

Give reference in index.html file

index.html

indexSer

Output:

outFact

View original post

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s