The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Services, Factories, and Providers: Creating a Service

Services, Factories, and Providers: Creating a Service

3:45
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 service function is just a constructor function.
Watch this lesson now
Avatar
egghead.io

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 service function is just a constructor function.

Avatar
Tim

In this video we call the .service as chained method, is this the best way to do this for this controller? This method over creating the service in separate service file and injecting it into the controller, which would be best for decoupling, performance, etc. ?

In reply to egghead.io
Avatar
Craig

Thanks for your question Tim. In a production application the module code, service code, and controller code would each be in their own file. I put them together here so that all the code could be seen together on one screen with the thought that it would be easier to understand the code. Note that the code in this example is still being injected in the controller and is decoupled it just is a good practice to keep things in separate files which I am not doing here.

In reply to Tim
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?