The function you pass in .serviceis called with new, so it is already basically a constructor. This is a "constructor function", and it implicitly returns an object that is singleton:
angular.module('myApp').service('helloService',function($timeout){
this.sayHello=function(name){
}
});
, .service ES6 ( ) -, , :
class HelloService {
constructor($timeout) {
}
sayHello(name) {
}
}
angular.module('myApp').service('helloService', HelloService);
.factory , new. , , , singleton :
angular.module('myApp').factory('helloService',function($timeout){
return {
sayHello: function(name) {
}
};
});
. @Vladimir Zdenek, "" . " , ?". , , , "".