I'm getting re-acquainted with angular after a long time away, and (so far) I've discovered two ways to create an angular service. The simplest being this:
var app = angular.Module("SomeApp", [])
.factory("SomeService", function ($log) {
$log.info("Yea beh beh! Dis hea is a service!")
});
This form of creating a service in angular is documented in angular.Module.factory. But, you can also see, that on the same page there is another way to create a service, using angular.Module.service.
Reading the two descriptions, I am unable to understand the differences other than .service
needs you to explicitly use new
to instantiate a service, whereas .factory
implicitly does it for you. I might be wrong here, since I'm unable to understand because I have no clue what a $get
property is. So, to wrap up:
- What is a
$get
property? - What is the difference between
.service
and.factory
?
Lastly, because this bugs me:
- With all
angular.Module.{service, factory, controller}
, the second argument is afunction
. But, for instance, you have put in a list for the second argument in acontroller
, and name its dependencies. Then why is the type taken to be afunction
, rather thanobject
? I mean you won't know from the documentation that you can declare dependencies in a list unless you've done a tutorial or something.