As per the angular js docs
service(name, constructor); name : name constructor : An injectable class (constructor function) that will be instantiated.
Internally :
{
$get: function() {
return $injector.instantiate(constructor);
}
}
It could be concluded from the angular docs that service treats the 2nd argument passed as a constructor and provider creates an instance through $injector and returns through $get. So whenever we will inject the service in any of our module functions(controllers , directives etc) it should return the newly created object which is Singleton offcourse.
Now the problem comes here if I define my service like these ways.
1. _app_user_content.service("MyService" , function(){
this.Message = "Greetings!";
}); //returns object when injected.
2. _app_user_content.service("MyService" , function(){
this.Message = "Greetings!";
return "123"
}); // returns object when injected.
3. _app_user_content.service("MyService" , function(){
this.Message = "Greetings!";
return function(){}
}); //returns function(){} when injected. Doesnot return object
Why does the third case return a function?