I am just starting out with Angular. Reading the example of a service in the Google documentation, I just wonder why you would choose to use a service rather keeping the var
Based on my experience, services come in handy in the following scenarios:
When you wish to share information between two or more controllers
One may use $rootScope to also communicate between controllers, but as the common pitfalls section of the documentation suggests, it should be avoided as much as possible since it is a global scope. Using services,we can define setter and getter methods that can be easily used to exchange data between controllers.
When a functionality is to be used multiple times
Lets say that you have a functionality which repeats across all the templates that you have - say something in which you need to repeatedly convert the currency from USD to Euro and display the amount to the user. Here you can assume the "amount" to be anything from Purchasing Flight tickets, buying some books online - anything money related.
This functionality will be used across all your templates to display the amount always in Euro to the customer - but in your database / model, the amount is stored in Euro.
Thus, you can create a service that converts the amount from USD to Euro. Any controller can call it and use it. Your functionality is now located in one single place instead across controllers. So, in the future if you decide to make changes and display the amount in Pounds, you need to make the change only in one location and it will be reflected across all the controllers making use of it.
There are some other use cases but only these currently come to my mind right now. The most frequent use case that I find using services myself is point #1 - passing data between controllers.