diff --git a/src/ng/compile.js b/src/ng/compile.js index 995eaf23730e..cbd7975f5846 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1072,7 +1072,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { transclude: options.transclude, scope: {}, bindToController: options.bindings || {}, - restrict: 'E' + restrict: 'E', + require: options.require, + link: options.controllersReady && function(scope, element, attrs, controllers) { + options.controllersReady.apply(options, isArray(controllers) ? controllers : [controllers]); + } }; } diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index f885d3106433..bb2d10a23952 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -9435,5 +9435,37 @@ describe('$compile', function() { })); }); }); + + it('should call `controllersReady` with required controllers, if provided', function() { + var controllersReadySpy = jasmine.createSpy('controllersReady'); + function MeController() { this.name = 'Me'; } + function ParentController() { this.name = 'Parent'; } + function SiblingController() { this.name = 'Sibling'; } + + angular.module('my', []) + .component('me', { + require: ['me', '^parent', 'sibling'], + controllersReady: controllersReadySpy, + controller: MeController + }) + .component('parent', { + controller: ParentController + }) + .directive('sibling', function() { + return { + controller: SiblingController + }; + }); + + module('my'); + inject(function($compile, $rootScope, meDirective) { + element = $compile('')($rootScope); + expect(controllersReadySpy).toHaveBeenCalledWith( + jasmine.any(MeController), + jasmine.any(ParentController), + jasmine.any(SiblingController) + ); + }); + }); }); });