Skip to content

Commit ef4cd8d

Browse files
committed
fix(loader): allow 'ng' module to be extended with filters/directives/etc
Due to a regression in c0b4e2d, it is no longer possible to add new controllers, directives, filters, or animations to the `ng` module. This is becuase `config` blocks are always evaluated after regular invoke blocks, and the registration of these types depend on angular's config blocks to have been run. This solution simply ensures that `ng`'s config blocks are run before its invoke blocks are run. Closes angular#7709
1 parent 2f0a448 commit ef4cd8d

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/auto/injector.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,10 @@ function createInjector(modulesToLoad, strictDi) {
712712
if (isString(module)) {
713713
moduleFn = angularModule(module);
714714
runBlocks = runBlocks.concat(loadModules(moduleFn.requires)).concat(moduleFn._runBlocks);
715+
var isCore = module === 'ng';
716+
if (isCore) runInvokeQueue(moduleFn._configBlocks);
715717
runInvokeQueue(moduleFn._invokeQueue);
716-
runInvokeQueue(moduleFn._configBlocks);
718+
if (!isCore) runInvokeQueue(moduleFn._configBlocks);
717719
} else if (isFunction(module)) {
718720
runBlocks.push(providerInjector.invoke(module));
719721
} else if (isArray(module)) {

test/loaderSpec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,46 @@ describe('module loader', function() {
8484
it('should expose `$$minErr` on the `angular` object', function() {
8585
expect(window.angular.$$minErr).toEqual(jasmine.any(Function));
8686
});
87+
88+
describe('extending "ng" module', function() {
89+
var rootElement, angular, run;
90+
beforeEach(function() {
91+
rootElement = jqLite('<div></div>');
92+
jqLite(document.body).append(rootElement);
93+
angular = window.angular;
94+
publishExternalAPI(angular);
95+
run = jasmine.createSpy('run block');
96+
});
97+
98+
afterEach(function() {
99+
expect(run).toHaveBeenCalledOnce();
100+
rootElement.remove();
101+
dealoc(rootElement);
102+
});
103+
104+
it('should allow filters to be registered', function() {
105+
run.andCallFake(function($filter) { expect($filter('noop')).toBe(noop); });
106+
angularModule("ng").filter('noop', function() { return noop; }).run(['$filter', run]);
107+
angular.bootstrap(rootElement, []);
108+
});
109+
110+
it('should allow directives to be registered', function() {
111+
var linkMe = jasmine.createSpy('linkMe');
112+
run.andCallFake(function($compile, $rootScope) {
113+
dealoc($compile('<div link-me></div>')($rootScope));
114+
expect(linkMe).toHaveBeenCalledOnce();
115+
});
116+
angularModule("ng").directive('linkMe', valueFn(linkMe)).run(['$compile', '$rootScope', run]);
117+
angular.bootstrap(rootElement, []);
118+
});
119+
120+
it('should allow controllers to be registered', function() {
121+
function Ctrl($scope) {}
122+
run.andCallFake(function($controller, $rootScope) {
123+
expect($controller('Ctrl', { $scope: $rootScope }) instanceof Ctrl).toBe(true);
124+
});
125+
angularModule("ng").controller('Ctrl', Ctrl).run(['$controller', '$rootScope', run]);
126+
angular.bootstrap(rootElement, []);
127+
});
128+
});
87129
});

0 commit comments

Comments
 (0)