diff --git a/src/ng/compile.js b/src/ng/compile.js index 5449366e85e9..33fd1d8e5322 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1092,7 +1092,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { * See also {@link ng.$compileProvider#directive $compileProvider.directive()}. */ this.component = function registerComponent(name, options) { - var controller = options.controller || noop; + var controller = options.controller || function() {}; function factory($injector) { function makeInjectable(fn) { diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index f3bb5c802438..a08938c6b2fb 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -10494,7 +10494,7 @@ describe('$compile', function() { }); it('should expose additional annotations on the directive definition object', function() { - var myModule = angular.module('my', []).component('myComponent', { + angular.module('my', []).component('myComponent', { $canActivate: 'canActivate', $routeConfig: 'routeConfig', $customAnnotation: 'XXX' @@ -10510,7 +10510,7 @@ describe('$compile', function() { }); it('should support custom annotations if the controller is named', function() { - var myModule = angular.module('my', []).component('myComponent', { + angular.module('my', []).component('myComponent', { $customAnnotation: 'XXX', controller: 'SomeNamedController' }); @@ -10522,6 +10522,24 @@ describe('$compile', function() { }); }); + it('should provide a new empty controller if none is specified', function() { + angular. + module('my', []). + component('myComponent1', {$customAnnotation1: 'XXX'}). + component('myComponent2', {$customAnnotation2: 'YYY'}); + module('my'); + inject(function(myComponent1Directive, myComponent2Directive) { + var ctrl1 = myComponent1Directive[0].controller; + var ctrl2 = myComponent2Directive[0].controller; + + expect(ctrl1).not.toBe(ctrl2); + expect(ctrl1.$customAnnotation1).toBe('XXX'); + expect(ctrl1.$customAnnotation2).toBeUndefined(); + expect(ctrl2.$customAnnotation1).toBeUndefined(); + expect(ctrl2.$customAnnotation2).toBe('YYY'); + }); + }); + it('should return ddo with reasonable defaults', function() { angular.module('my', []).component('myComponent', {}); module('my');