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

fix(loader): allow 'ng' module to be extended with filters/directives/etc #7880

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/auto/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,10 @@ function createInjector(modulesToLoad, strictDi) {
if (isString(module)) {
moduleFn = angularModule(module);
runBlocks = runBlocks.concat(loadModules(moduleFn.requires)).concat(moduleFn._runBlocks);
var isCore = module === 'ng';
if (isCore) runInvokeQueue(moduleFn._configBlocks);
runInvokeQueue(moduleFn._invokeQueue);
runInvokeQueue(moduleFn._configBlocks);
if (!isCore) runInvokeQueue(moduleFn._configBlocks);
} else if (isFunction(module)) {
runBlocks.push(providerInjector.invoke(module));
} else if (isArray(module)) {
Expand Down
42 changes: 42 additions & 0 deletions test/loaderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,46 @@ describe('module loader', function() {
it('should expose `$$minErr` on the `angular` object', function() {
expect(window.angular.$$minErr).toEqual(jasmine.any(Function));
});

describe('extending "ng" module', function() {
var rootElement, angular, run;
beforeEach(function() {
rootElement = jqLite('<div></div>');
jqLite(document.body).append(rootElement);
angular = window.angular;
publishExternalAPI(angular);
run = jasmine.createSpy('run block');
});

afterEach(function() {
expect(run).toHaveBeenCalledOnce();
rootElement.remove();
dealoc(rootElement);
});

it('should allow filters to be registered', function() {
run.andCallFake(function($filter) { expect($filter('noop')).toBe(noop); });
angularModule("ng").filter('noop', function() { return noop; }).run(['$filter', run]);
angular.bootstrap(rootElement, []);
});

it('should allow directives to be registered', function() {
var linkMe = jasmine.createSpy('linkMe');
run.andCallFake(function($compile, $rootScope) {
dealoc($compile('<div link-me></div>')($rootScope));
expect(linkMe).toHaveBeenCalledOnce();
});
angularModule("ng").directive('linkMe', valueFn(linkMe)).run(['$compile', '$rootScope', run]);
angular.bootstrap(rootElement, []);
});

it('should allow controllers to be registered', function() {
function Ctrl($scope) {}
run.andCallFake(function($controller, $rootScope) {
expect($controller('Ctrl', { $scope: $rootScope }) instanceof Ctrl).toBe(true);
});
angularModule("ng").controller('Ctrl', Ctrl).run(['$controller', '$rootScope', run]);
angular.bootstrap(rootElement, []);
});
});
});