aboutsummaryrefslogtreecommitdiffstats
path: root/src/Compiler.js
diff options
context:
space:
mode:
authorMisko Hevery2010-10-08 17:30:13 -0700
committerMisko Hevery2010-10-12 16:33:06 -0700
commitd9abfe8a7e488be8725f56077527b16f7c79546a (patch)
tree67089c5d2059e7a56afab0fec19dbce76fdab798 /src/Compiler.js
parentfbfd160316de1b99e7afa4102c7fae2ee5b9c1f5 (diff)
downloadangular.js-d9abfe8a7e488be8725f56077527b16f7c79546a.tar.bz2
Introduced injector and $new to scope, and injection into link methods and controllers
- added angular.injector(scope, services, instanceCache) which returns inject - inject method can return, instance, or call function which have $inject property - initialize services with $creation=[eager|eager-publish] this means that only some of the services are now globally accessible - upgraded $become on scope to use injector hence respect the $inject property for injection - $become should not be run multiple times and will most likely be removed in future version - added $new on scope to create a child scope - $inject is respected on constructor function - simplified scopes so that they no longer have separate __proto__ for parent, api, behavior and instance this should speed up execution since scope will now create one __proto__ chain per scope (not three). BACKWARD COMPATIBILITY WARNING: - services now need to have $inject instead of inject property for proper injection this breaks backward compatibility - not all services are now published into root scope (only: $location, $cookie, $window) - if you have widget/directive which uses services on scope (such as this.$xhr), you will now have to inject that service in (as it is not published on the root scope anymore)
Diffstat (limited to 'src/Compiler.js')
-rw-r--r--src/Compiler.js7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/Compiler.js b/src/Compiler.js
index 0c80d3fc..a78a04c9 100644
--- a/src/Compiler.js
+++ b/src/Compiler.js
@@ -34,7 +34,7 @@ Template.prototype = {
foreach(this.inits, function(fn) {
queue.push(function() {
childScope.$tryEval(function(){
- return fn.call(childScope, element);
+ return childScope.$inject(fn, childScope, element);
}, element);
});
});
@@ -96,8 +96,7 @@ Compiler.prototype = {
return function(element, parentScope){
element = jqLite(element);
var scope = parentScope && parentScope.$eval ?
- parentScope :
- createScope(parentScope || {}, angularService);
+ parentScope : createScope(parentScope);
return extend(scope, {
$element:element,
$init: function() {
@@ -124,7 +123,7 @@ Compiler.prototype = {
text:function(text) {return jqLite(document.createTextNode(text));},
descend: function(value){ if(isDefined(value)) descend = value; return descend;},
directives: function(value){ if(isDefined(value)) directives = value; return directives;},
- scope: function(value){ if(isDefined(value)) template.newScope = template.newScope || value ; return template.newScope;}
+ scope: function(value){ if(isDefined(value)) template.newScope = template.newScope || value; return template.newScope;}
};
try {
priority = element.attr('ng:eval-order') || priority || 0;