Services, Factories, and Providers: Creating a Factory

Share this video with your friends

Send Tweet

Creating your own services in AngularJS can be confusing. What are the differences between an AngularJS module's Service, Provider and Factory functions? This lesson shows how Angular's factory function is just the JavaScript module design pattern.

Sergey
Sergey
~ 9 years ago

Was hoping to learn if there are any particular scenarios to choose Service over Factory or vice versa.

Craig McKeachie
Craig McKeachie(instructor)
~ 9 years ago

I still have a few more video to record and add to the playlist that go over the tradeoffs but for the most part it's more of a coding style thing than any actual performance or practical difference. For example, Service services lend themselves to using ES6/ES2015 classes or an object oriented style while Factories let you use a module or revealing module style of coding. That said if you want inheritance you would lean towards the service recipe.

Sergey
Sergey
~ 9 years ago

Thanks! Looking forward to seeng new episodes.

Augusto Toledo
Augusto Toledo
~ 7 years ago

If we were to add another controller and inject the droid factory, angular would reuse the same instance and would not create a new one?

Craig McKeachie
Craig McKeachie(instructor)
~ 7 years ago

Yes, you are correct it would be a singleton.