Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 8adae2f

Browse files
committed
refactor(injector): removed loadModule/ng:module
- added module property to doc:example
1 parent 9555511 commit 8adae2f

7 files changed

+46
-70
lines changed

docs/content/guide/dev_guide.services.injecting_controllers.ngdoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ this.secondMethod = function() {
2828
myController.$inject = ['$location', '$log'];
2929
</pre>
3030

31-
<doc:example>
31+
<doc:example module="MyServiceModule">
3232
<doc:source>
3333
<script type="text/javascript">
3434
angular.module.MyServiceModule = ['$provide', function($provide){
@@ -53,7 +53,7 @@ function myController(notifyService) {
5353
myController.$inject = ['notify'];
5454
</script>
5555

56-
<div ng:controller="myController" ng:module="MyServiceModule">
56+
<div ng:controller="myController">
5757
<p>Let's try this simple notify service, injected into the controller...</p>
5858
<input ng:init="message='test'" type="text" ng:model="message" />
5959
<button ng:click="callNotify(message);">NOTIFY</button>

docs/content/guide/dev_guide.templates.filters.creating_filters.ngdoc

+20-20
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@ filter to manipulate the DOM.
1616
The following sample filter reverses a text string. In addition, it conditionally makes the
1717
text upper-case and assigns color.
1818

19-
<doc:example>
19+
<doc:example module="MyReverseModule">
2020
<doc:source>
2121
<script type="text/javascript">
22-
angular.module.MyReverseModule = function MyModule($filterProvider) {
23-
$filterProvider.register('reverse', function() {
24-
return function(input, uppercase) {
25-
var out = "";
26-
for (var i = 0; i < input.length; i++) {
27-
out = input.charAt(i) + out;
28-
}
29-
// conditional based on optional argument
30-
if (uppercase) {
31-
out = out.toUpperCase();
32-
}
33-
return out;
34-
}
35-
});
36-
}
22+
angular.module.MyReverseModule = function ($filterProvider) {
23+
$filterProvider.register('reverse', function() {
24+
return function(input, uppercase) {
25+
var out = "";
26+
for (var i = 0; i < input.length; i++) {
27+
out = input.charAt(i) + out;
28+
}
29+
// conditional based on optional argument
30+
if (uppercase) {
31+
out = out.toUpperCase();
32+
}
33+
return out;
34+
}
35+
});
36+
}
3737

38-
function Ctrl() {
39-
this.greeting = 'hello';
40-
}
38+
function Ctrl() {
39+
this.greeting = 'hello';
40+
}
4141
</script>
4242

43-
<div ng:controller="Ctrl" ng:module="MyReverseModule">
43+
<div ng:controller="Ctrl">
4444
<input ng:model="greeting" type="greeting"><br>
4545
No filter: {{greeting}}<br>
4646
Reverse: {{greeting|reverse}}<br>

docs/src/templates/doc_widgets.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
var HTML_TEMPLATE =
1616
'<!doctype html>\n' +
1717
'<html xmlns:ng="http://angularjs.org">\n' +
18-
' <script src="' + angularJsUrl + '" ng:autobind></script>\n' +
18+
' <script src="' + angularJsUrl + '" ng:autobind_MODULE_></script>\n' +
1919
' <body>\n' +
2020
'_HTML_SOURCE_\n' +
2121
' </body>\n' +
2222
'</html>';
2323

24-
angular.widget('doc:example', function(element){
24+
angular.widget('doc:example', ['$injector', '$element', function($injector, element){
2525
this.descend(true); //compile the example code
26+
var module = element.attr('module');
2627

2728
//jQuery find() methods in this widget contain primitive selectors on purpose so that we can use
2829
//jqlite instead. jqlite's find() method currently supports onlt getElementsByTagName!
@@ -59,7 +60,10 @@
5960
'</ul>';
6061
var tabs = angular.element(tabHtml);
6162

62-
tabs.find('li').eq(1).find('pre').text(HTML_TEMPLATE.replace('_HTML_SOURCE_', code.html));
63+
tabs.find('li').eq(1).find('pre').text(
64+
HTML_TEMPLATE.
65+
replace('_HTML_SOURCE_', code.html).
66+
replace('_MODULE_', (module ? (' ng:module="' + module + '"') : '')));
6367

6468
element.html('');
6569
element.append(tabs);
@@ -76,6 +80,11 @@
7680
alert(e);
7781
}
7882

83+
if (module) {
84+
$injector.invoke(null, angular.module[module]);
85+
}
86+
87+
7988
function jsFiddleButton(jsfiddle) {
8089
if (jsfiddle !== 'false') {
8190
if(jsfiddle === true) {
@@ -100,7 +109,7 @@
100109
'</textarea>' +
101110
'<input type="text" name="title" value="AngularJS Live Example">' +
102111
'<textarea name="html">' +
103-
'<script src="' + angularJsUrl + '" ng:autobind></script>\n\n' +
112+
'<script src="' + angularJsUrl + '" ng:autobind' + (module ? (' ng:module="' + module + '"') : '') + '></script>\n\n' +
104113
'<!-- AngularJS Example Code: -->\n\n' +
105114
fiddleSrc +
106115
'</textarea>' +
@@ -116,7 +125,7 @@
116125
}
117126
return '';
118127
}
119-
});
128+
}]);
120129

121130
function indent(text) {
122131
if (!text) return text;

src/Injector.js

+1-18
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,6 @@ function inferInjectionArgs(fn) {
140140
* @return new instance of `Type`.
141141
*/
142142

143-
/**
144-
* @ngdoc method
145-
* @name angular.module.AUTO.$injector#loadModule
146-
* @methodOf angular.module.AUTO.$injector
147-
* @description
148-
* Load additional modules into the current injector configuration
149-
*
150-
* @param {Array} modules An array of modules, where module is a:
151-
*
152-
* - `string`: look up the module function from {@link angular.module} and then treat as `function`.
153-
* - `function`: execute the module configuration function using
154-
* {@link angular.module.AUTO.$injector#invoke $injector.invoke()}
155-
*/
156-
157-
158143

159144
/**
160145
* @ngdoc object
@@ -255,15 +240,13 @@ function inferInjectionArgs(fn) {
255240
function createInjector(modulesToLoad, moduleRegistry) {
256241
var cache = {},
257242
providerSuffix = 'Provider',
258-
providerSuffixLength = providerSuffix.length,
259243
path = [],
260244
$injector;
261245

262246
value('$injector', $injector = {
263247
get: getService,
264248
invoke: invoke,
265-
instantiate: instantiate,
266-
loadModule: loadModule
249+
instantiate: instantiate
267250
});
268251
value('$provide', {
269252
service: service,

src/directives.js

-9
Original file line numberDiff line numberDiff line change
@@ -887,12 +887,3 @@ angularDirective("ng:cloak", function(expression, element) {
887887
element.removeAttr('ng:cloak');
888888
element.removeClass('ng-cloak');
889889
});
890-
891-
angularDirective('ng:module', ['$value', '$injector',
892-
function(modules, $injector) {
893-
forEach(modules.split(','), function(module){
894-
if (module = trim(module)) {
895-
$injector.loadModule(module);
896-
}
897-
});
898-
}]);

src/service/compiler.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ function $CompileProvider(){
244244
elementName = nodeName_(element),
245245
elementNamespace = elementName.indexOf(':') > 0 ? lowercase(elementName).replace(':', '-') : '',
246246
template,
247+
locals = {$element: element},
247248
selfApi = {
248249
compile: bind(self, self.compile),
249250
descend: function(value){ if(isDefined(value)) descend = value; return descend;},
@@ -256,22 +257,27 @@ function $CompileProvider(){
256257
if (!widget) {
257258
if ((widget = self.widgets('@' + name))) {
258259
element.addClass('ng-attr-widget');
259-
widget = bind(selfApi, widget, value, element);
260+
if (isFunction(widget) && !widget.$inject) {
261+
widget.$inject = ['$value', '$element'];
262+
}
263+
locals.$value = value;
260264
}
261265
}
262266
});
263267
if (!widget) {
264268
if ((widget = self.widgets(elementName))) {
265269
if (elementNamespace)
266270
element.addClass('ng-widget');
267-
widget = bind(selfApi, widget, element);
271+
if (isFunction(widget) && !widget.$inject) {
272+
widget.$inject = ['$element'];
273+
}
268274
}
269275
}
270276
if (widget) {
271277
descend = false;
272278
directives = false;
273279
var parent = element.parent();
274-
template.addLinkFn(widget.call(selfApi, element));
280+
template.addLinkFn($injector.invoke(selfApi, widget, locals));
275281
if (parent && parent[0]) {
276282
element = jqLite(parent[0].childNodes[elementIndex]);
277283
}

test/directivesSpec.js

-13
Original file line numberDiff line numberDiff line change
@@ -535,17 +535,4 @@ describe("directive", function() {
535535
expect(element.hasClass('bar')).toBe(true);
536536
}));
537537
});
538-
539-
describe('ng:module', function() {
540-
it('should install the modules', inject(function($injector, $compile, $rootScope) {
541-
var log = '';
542-
var injector = $injector;
543-
angular.module.a = function($injector){ log += ($injector == injector) + ';';};
544-
angular.module.b = function($injector){ log += ($injector == injector); }
545-
$compile('<div ng:module=" a, ,,, b "></div>')($rootScope);
546-
expect(log).toEqual('true;true');
547-
delete angular.module.a;
548-
delete angular.module.b;
549-
}));
550-
});
551538
});

0 commit comments

Comments
 (0)