Crazy Bugs

Factory is used for re-usability

  • Ex. In OOPS, when code get repeated we uses re-usability concept as like inheritance
  • In Factory, design pattern used is Singleton. Here, only one object is created and stored in memory. This stored object is then shared by different components
  • Factory can be injected into other components like services, controllers and factory itself
  • Code is shared between controllers using factory
  • Clear separation of code

Process to create factory

Create custom module



Create custom factory

  • Create anonymous function
  • Create variable which stores data
  • Empty object as we have taken factory
  • On this empty object , create function getCustomers which is going to returns all customers
  • At last, factory object should be registered with module



Inject factory into controller

  • Take parameters as $scope and to inject factory as customerFactory
  • Create a function and call customerFactory’s function to get customers
  • Register controller with module




View original post 6 more words


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s