fix($compile): do not use noop() as controller for multiple components
Currently, custom annotations are copied from the CDO onto the controller constructor. Using `noop()` when no controller has been specified, pollutes it with custom annotations and makes one component's annotations available to all other components that have `noop()` as their controller. Fixes #14391 Closes #14402
This commit is contained in:
committed by
Peter Bacon Darwin
parent
a0b5e1a858
commit
9264cef03f
+1
-1
@@ -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) {
|
||||
|
||||
+22
-2
@@ -10538,7 +10538,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'
|
||||
@@ -10554,7 +10554,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'
|
||||
});
|
||||
@@ -10566,6 +10566,26 @@ 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');
|
||||
|
||||
Reference in New Issue
Block a user