mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
refactor(injector): removed loadModule/ng:module
- added module property to doc:example
This commit is contained in:
parent
955551141d
commit
8adae2fdf2
7 changed files with 46 additions and 70 deletions
|
|
@ -28,7 +28,7 @@ this.secondMethod = function() {
|
|||
myController.$inject = ['$location', '$log'];
|
||||
</pre>
|
||||
|
||||
<doc:example>
|
||||
<doc:example module="MyServiceModule">
|
||||
<doc:source>
|
||||
<script type="text/javascript">
|
||||
angular.module.MyServiceModule = ['$provide', function($provide){
|
||||
|
|
@ -53,7 +53,7 @@ function myController(notifyService) {
|
|||
myController.$inject = ['notify'];
|
||||
</script>
|
||||
|
||||
<div ng:controller="myController" ng:module="MyServiceModule">
|
||||
<div ng:controller="myController">
|
||||
<p>Let's try this simple notify service, injected into the controller...</p>
|
||||
<input ng:init="message='test'" type="text" ng:model="message" />
|
||||
<button ng:click="callNotify(message);">NOTIFY</button>
|
||||
|
|
|
|||
|
|
@ -16,31 +16,31 @@ filter to manipulate the DOM.
|
|||
The following sample filter reverses a text string. In addition, it conditionally makes the
|
||||
text upper-case and assigns color.
|
||||
|
||||
<doc:example>
|
||||
<doc:example module="MyReverseModule">
|
||||
<doc:source>
|
||||
<script type="text/javascript">
|
||||
angular.module.MyReverseModule = function MyModule($filterProvider) {
|
||||
$filterProvider.register('reverse', function() {
|
||||
return function(input, uppercase) {
|
||||
var out = "";
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
out = input.charAt(i) + out;
|
||||
}
|
||||
// conditional based on optional argument
|
||||
if (uppercase) {
|
||||
out = out.toUpperCase();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
});
|
||||
}
|
||||
angular.module.MyReverseModule = function ($filterProvider) {
|
||||
$filterProvider.register('reverse', function() {
|
||||
return function(input, uppercase) {
|
||||
var out = "";
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
out = input.charAt(i) + out;
|
||||
}
|
||||
// conditional based on optional argument
|
||||
if (uppercase) {
|
||||
out = out.toUpperCase();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function Ctrl() {
|
||||
this.greeting = 'hello';
|
||||
}
|
||||
function Ctrl() {
|
||||
this.greeting = 'hello';
|
||||
}
|
||||
</script>
|
||||
|
||||
<div ng:controller="Ctrl" ng:module="MyReverseModule">
|
||||
<div ng:controller="Ctrl">
|
||||
<input ng:model="greeting" type="greeting"><br>
|
||||
No filter: {{greeting}}<br>
|
||||
Reverse: {{greeting|reverse}}<br>
|
||||
|
|
|
|||
|
|
@ -15,14 +15,15 @@
|
|||
var HTML_TEMPLATE =
|
||||
'<!doctype html>\n' +
|
||||
'<html xmlns:ng="http://angularjs.org">\n' +
|
||||
' <script src="' + angularJsUrl + '" ng:autobind></script>\n' +
|
||||
' <script src="' + angularJsUrl + '" ng:autobind_MODULE_></script>\n' +
|
||||
' <body>\n' +
|
||||
'_HTML_SOURCE_\n' +
|
||||
' </body>\n' +
|
||||
'</html>';
|
||||
|
||||
angular.widget('doc:example', function(element){
|
||||
angular.widget('doc:example', ['$injector', '$element', function($injector, element){
|
||||
this.descend(true); //compile the example code
|
||||
var module = element.attr('module');
|
||||
|
||||
//jQuery find() methods in this widget contain primitive selectors on purpose so that we can use
|
||||
//jqlite instead. jqlite's find() method currently supports onlt getElementsByTagName!
|
||||
|
|
@ -59,7 +60,10 @@
|
|||
'</ul>';
|
||||
var tabs = angular.element(tabHtml);
|
||||
|
||||
tabs.find('li').eq(1).find('pre').text(HTML_TEMPLATE.replace('_HTML_SOURCE_', code.html));
|
||||
tabs.find('li').eq(1).find('pre').text(
|
||||
HTML_TEMPLATE.
|
||||
replace('_HTML_SOURCE_', code.html).
|
||||
replace('_MODULE_', (module ? (' ng:module="' + module + '"') : '')));
|
||||
|
||||
element.html('');
|
||||
element.append(tabs);
|
||||
|
|
@ -76,6 +80,11 @@
|
|||
alert(e);
|
||||
}
|
||||
|
||||
if (module) {
|
||||
$injector.invoke(null, angular.module[module]);
|
||||
}
|
||||
|
||||
|
||||
function jsFiddleButton(jsfiddle) {
|
||||
if (jsfiddle !== 'false') {
|
||||
if(jsfiddle === true) {
|
||||
|
|
@ -100,7 +109,7 @@
|
|||
'</textarea>' +
|
||||
'<input type="text" name="title" value="AngularJS Live Example">' +
|
||||
'<textarea name="html">' +
|
||||
'<script src="' + angularJsUrl + '" ng:autobind></script>\n\n' +
|
||||
'<script src="' + angularJsUrl + '" ng:autobind' + (module ? (' ng:module="' + module + '"') : '') + '></script>\n\n' +
|
||||
'<!-- AngularJS Example Code: -->\n\n' +
|
||||
fiddleSrc +
|
||||
'</textarea>' +
|
||||
|
|
@ -116,7 +125,7 @@
|
|||
}
|
||||
return '';
|
||||
}
|
||||
});
|
||||
}]);
|
||||
|
||||
function indent(text) {
|
||||
if (!text) return text;
|
||||
|
|
|
|||
|
|
@ -140,21 +140,6 @@ function inferInjectionArgs(fn) {
|
|||
* @return new instance of `Type`.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
* @name angular.module.AUTO.$injector#loadModule
|
||||
* @methodOf angular.module.AUTO.$injector
|
||||
* @description
|
||||
* Load additional modules into the current injector configuration
|
||||
*
|
||||
* @param {Array} modules An array of modules, where module is a:
|
||||
*
|
||||
* - `string`: look up the module function from {@link angular.module} and then treat as `function`.
|
||||
* - `function`: execute the module configuration function using
|
||||
* {@link angular.module.AUTO.$injector#invoke $injector.invoke()}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @ngdoc object
|
||||
|
|
@ -255,15 +240,13 @@ function inferInjectionArgs(fn) {
|
|||
function createInjector(modulesToLoad, moduleRegistry) {
|
||||
var cache = {},
|
||||
providerSuffix = 'Provider',
|
||||
providerSuffixLength = providerSuffix.length,
|
||||
path = [],
|
||||
$injector;
|
||||
|
||||
value('$injector', $injector = {
|
||||
get: getService,
|
||||
invoke: invoke,
|
||||
instantiate: instantiate,
|
||||
loadModule: loadModule
|
||||
instantiate: instantiate
|
||||
});
|
||||
value('$provide', {
|
||||
service: service,
|
||||
|
|
|
|||
|
|
@ -887,12 +887,3 @@ 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);
|
||||
}
|
||||
});
|
||||
}]);
|
||||
|
|
|
|||
|
|
@ -244,6 +244,7 @@ function $CompileProvider(){
|
|||
elementName = nodeName_(element),
|
||||
elementNamespace = elementName.indexOf(':') > 0 ? lowercase(elementName).replace(':', '-') : '',
|
||||
template,
|
||||
locals = {$element: element},
|
||||
selfApi = {
|
||||
compile: bind(self, self.compile),
|
||||
descend: function(value){ if(isDefined(value)) descend = value; return descend;},
|
||||
|
|
@ -256,7 +257,10 @@ function $CompileProvider(){
|
|||
if (!widget) {
|
||||
if ((widget = self.widgets('@' + name))) {
|
||||
element.addClass('ng-attr-widget');
|
||||
widget = bind(selfApi, widget, value, element);
|
||||
if (isFunction(widget) && !widget.$inject) {
|
||||
widget.$inject = ['$value', '$element'];
|
||||
}
|
||||
locals.$value = value;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -264,14 +268,16 @@ function $CompileProvider(){
|
|||
if ((widget = self.widgets(elementName))) {
|
||||
if (elementNamespace)
|
||||
element.addClass('ng-widget');
|
||||
widget = bind(selfApi, widget, element);
|
||||
if (isFunction(widget) && !widget.$inject) {
|
||||
widget.$inject = ['$element'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (widget) {
|
||||
descend = false;
|
||||
directives = false;
|
||||
var parent = element.parent();
|
||||
template.addLinkFn(widget.call(selfApi, element));
|
||||
template.addLinkFn($injector.invoke(selfApi, widget, locals));
|
||||
if (parent && parent[0]) {
|
||||
element = jqLite(parent[0].childNodes[elementIndex]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -535,17 +535,4 @@ describe("directive", function() {
|
|||
expect(element.hasClass('bar')).toBe(true);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('ng:module', function() {
|
||||
it('should install the modules', inject(function($injector, $compile, $rootScope) {
|
||||
var log = '';
|
||||
var injector = $injector;
|
||||
angular.module.a = function($injector){ log += ($injector == injector) + ';';};
|
||||
angular.module.b = function($injector){ log += ($injector == injector); }
|
||||
$compile('<div ng:module=" a, ,,, b "></div>')($rootScope);
|
||||
expect(log).toEqual('true;true');
|
||||
delete angular.module.a;
|
||||
delete angular.module.b;
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue