constant, decorator, factory, provider, service, value
whoa.
this: http://goo.gl/xtuF1
Dependency Injection.
Modularization.
Testing.
Injected singletons with a $get method, essentially.
app.constant('jellyBean', 4.2);
app.value('name', 'Larry');
app.service('api', function (dep) {...});
app.factory('widget', function (dep) {... return ?;})
app.config(function($provide) {
$provide.decorate('name', function($delegate) {
// Modifications to the 'name' provision.
return $delegate + ' the Great';
});
});
$provide.provider('foo', {$get: function(dep) {...}});
$provide.provider('foo', function(){
this.$get = function(dep) {...}
});
app.value('v', 7);
app.config(function(c) { }); // config-c
app.config(function(v) { }); // config-v
app.config(function($provide) { // config-p
$provide.provider('p', {
$get: function(v) { }
});
});
app.constant('c', function(v) { });
app.factory('f', function(v) { });
app.factory('x', function(v) { });
app.run(function(v) { });
app.service('s', function(v) { });
app.value('w', function(v) { });
app.controller('ctrl', function(v, c, w, f, p, s) { ... });
app.config can't take a 'value'.
conf-c,
conf-p,
run,
f,
p,
s,
x
v: 7, c: fn, w: fn, f: undef, p: undef, s: {}
QED
app.config(function($provide) {
$provide.provider('x', {
$get: function() {
// ???
}
});
});
Questions, comments?
this: http://goo.gl/xtuF1