I'm learning angular1 and I came across services and factories. I called the .factory()
method as shown below by passing in a string representing the desired service name. I was later able to reference a variable identical to the string name but I never actually created the variable. Does anyone know why this is the case? I imagine it's something to do with dependency injection but I can't understand the mechanism by which angular/js achieves this auto-variable creation.
app.factory('myData', function() {
return {...}
}
app.controller('MyController',
function MyController($scope, myData) {
...
}
);