Answer the question
In order to leave comments, you need to log in
`
AngularJS - why wrap service`s in a factory?
Here , in the file modules/authentication/services.js
service.Login
, service.SetCredentials
and service.ClearCredentials
are in factory('AuthenticationService')
What does it give?
After all, you can simply take it out to separate services ..
Answer the question
In order to leave comments, you need to log in
I solved the problem, because he saw a card reader under this disk F, turned it off, the error disappeared)
Mb will help someone)
Have a good day everyone!
functions Login, SetCredentials, etc. are methods of the AuthenticationService service .
A factory is a way to define a service. The only difference between .service and .factory is that in the first case you put in an object constructor, and in the second - a factory function that will figure out how to create an object.
// вот сервис
function MyService (dep1, dep2) {
this.dep1 = dep1;
this.dep2 = dep2;
}
// А вот фабрика этого сервиса
function myServiceFactory(dep1, dep2) {
return new MyService(dep1, dep2);
}
// в результате в контейнере зависимостей будет крутиться
// 2 инстанса одного и того же сервиса. То есть одинаковый результат
// при двух подходах.
module.service('foo', MyService)
module.factory('bar', myServiceFactory);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question