aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMisko Hevery2011-11-08 17:40:03 -0800
committerMisko Hevery2011-11-14 20:31:15 -0800
commit085e3c611fd0cd48757702c50c67b551a00a0d38 (patch)
tree879f19d0a829c828c3636b38c8c422f732a829a9 /src
parent4b35a59c6afd5093ed5ce7d68b75ccadd4c53696 (diff)
downloadangular.js-085e3c611fd0cd48757702c50c67b551a00a0d38.tar.bz2
new(directive): added ng:module directive for loading modules
Diffstat (limited to 'src')
-rw-r--r--src/Angular.js1
-rw-r--r--src/AngularPublic.js4
-rw-r--r--src/Injector.js31
-rw-r--r--src/directives.js16
-rw-r--r--src/service/compiler.js14
5 files changed, 40 insertions, 26 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 7b9bd1db..a191c0c7 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -1028,6 +1028,7 @@ function publishExternalAPI(angular){
'copy': copy,
'extend': extend,
'equals': equals,
+ 'element': jqLite,
'forEach': forEach,
'injector': function(){ return createInjector(arguments, angularModule); },
'noop':noop,
diff --git a/src/AngularPublic.js b/src/AngularPublic.js
index 64a7bf4d..6403c4ff 100644
--- a/src/AngularPublic.js
+++ b/src/AngularPublic.js
@@ -1,9 +1,7 @@
'use strict';
-publishExternalAPI(angular);
-
//try to bind to jquery now so that one can write angular.element().read()
//but we will rebind on bootstrap again.
bindJQuery();
-
+publishExternalAPI(angular);
diff --git a/src/Injector.js b/src/Injector.js
index eacb8699..58b30fda 100644
--- a/src/Injector.js
+++ b/src/Injector.js
@@ -167,24 +167,29 @@ function createInjector(modulesToLoad, moduleRegistry) {
instance = new Constructor();
return invoke(instance, Type, locals) || instance;
};
+ injector.loadModule = loadModule;
return injector;
}
-
- forEach(modulesToLoad, function(module){
- if (isString(module)) {
- if (moduleRegistry[module]) {
- module = moduleRegistry[module];
+ function loadModule(modulesToLoad){
+ forEach(isString(modulesToLoad) ? modulesToLoad.split(',') : modulesToLoad, function(module) {
+ if (isString(module)) {
+ if (moduleRegistry[module = trim(module)]) {
+ module = moduleRegistry[module];
+ } else {
+ throw Error("Module '" + module + "' is not defined!");
+ }
+ }
+ if (isFunction(module) || isArray(module)) {
+ $injector(module);
} else {
- throw Error("Module '" + module + "' is not defined!");
+ assertArgFn(module, 'module');
}
- }
- if (isFunction(module) || isArray(module)) {
- $injector(module);
- } else {
- assertArgFn(module, 'module');
- }
- });
+ });
+ }
+
+
+ loadModule(modulesToLoad);
// instantiate $eager providers
// for perf we can't do forEach
diff --git a/src/directives.js b/src/directives.js
index b511541f..9361f08f 100644
--- a/src/directives.js
+++ b/src/directives.js
@@ -690,8 +690,7 @@ angularDirective("ng:class-odd", ngClass(function(i){return i % 2 === 0;}));
<doc:source>
<ol ng:init="names=['John', 'Mary', 'Cate', 'Suz']">
<li ng:repeat="name in names">
- <span ng:class-odd="'ng-format-negative'"
- ng:class-even="'ng-input-indicator-wait'">
+ <span ng:class-odd="'odd'" ng:class-even="'even'">
{{name}} &nbsp; &nbsp; &nbsp;
</span>
</li>
@@ -700,9 +699,9 @@ angularDirective("ng:class-odd", ngClass(function(i){return i % 2 === 0;}));
<doc:scenario>
it('should check ng:class-odd and ng:class-even', function() {
expect(element('.doc-example-live li:first span').prop('className')).
- toMatch(/ng-format-negative/);
+ toMatch(/odd/);
expect(element('.doc-example-live li:last span').prop('className')).
- toMatch(/ng-input-indicator-wait/);
+ toMatch(/even/);
});
</doc:scenario>
</doc:example>
@@ -888,3 +887,12 @@ angularDirective("ng:cloak", function(expression, element) {
element.removeAttr('ng:cloak');
element.removeClass('ng-cloak');
});
+
+angularDirective('ng:module', ['$value', '$injector',
+ function(modules, $injector) {
+ forEach(modules.split(','), function(module){
+ if (module = trim(module)) {
+ $injector.loadModule(module);
+ }
+ });
+}]);
diff --git a/src/service/compiler.js b/src/service/compiler.js
index 220d9c39..1bd2cbe0 100644
--- a/src/service/compiler.js
+++ b/src/service/compiler.js
@@ -27,7 +27,11 @@ function $CompileProvider(){
}
forEach(this.linkFns, function(fn) {
try {
- $injector.invoke(childScope, fn, locals);
+ if (isArray(fn) || fn.$inject) {
+ $injector.invoke(childScope, fn, locals);
+ } else {
+ fn.call(childScope, element);
+ }
} catch (e) {
$exceptionHandler(e);
}
@@ -52,10 +56,6 @@ function $CompileProvider(){
addLinkFn:function(linkingFn) {
if (linkingFn) {
- //TODO(misko): temporary hack.
- if (isFunction(linkingFn) && !linkingFn.$inject) {
- linkingFn.$inject = ['$element'];
- }
this.linkFns.push(linkingFn);
}
},
@@ -298,7 +298,9 @@ function $CompileProvider(){
fn = directiveFns[name];
if (fn) {
element.addClass('ng-directive');
- template.addLinkFn((directiveFns[name]).call(selfApi, value, element));
+ template.addLinkFn((isArray(fn) || fn.$inject)
+ ? $injector.invoke(selfApi, fn, {$value:value, $element: element})
+ : fn.call(selfApi, value, element));
}
});
}