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

Commit f338e96

Browse files
feat($compile): put custom annotations on DDO
Closes #14369 Closes #14279 Closes #14284
1 parent 0ad2b70 commit f338e96

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/ng/compile.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
11061106
}
11071107

11081108
var template = (!options.template && !options.templateUrl ? '' : options.template);
1109-
return {
1109+
var ddo = {
11101110
controller: controller,
11111111
controllerAs: identifierForController(options.controller) || options.controllerAs || '$ctrl',
11121112
template: makeInjectable(template),
@@ -1117,9 +1117,21 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
11171117
restrict: 'E',
11181118
require: options.require
11191119
};
1120+
1121+
// Copy annotations (starting with $) over to the DDO
1122+
forEach(options, function(val, key) {
1123+
if (key.charAt(0) === '$') ddo[key] = val;
1124+
});
1125+
1126+
return ddo;
11201127
}
11211128

1122-
// Copy any annotation properties (starting with $) over to the factory function
1129+
// TODO(pete) remove the following `forEach` before we release 1.6.0
1130+
// The [email protected] looks for the annotations on the controller constructor
1131+
// Nothing in Angular looks for annotations on the factory function but we can't remove
1132+
// it from 1.5.x yet.
1133+
1134+
// Copy any annotation properties (starting with $) over to the factory and controller constructor functions
11231135
// These could be used by libraries such as the new component router
11241136
forEach(options, function(val, key) {
11251137
if (key.charAt(0) === '$') {

test/ng/compileSpec.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -10461,22 +10461,35 @@ describe('$compile', function() {
1046110461
}));
1046210462
});
1046310463

10464-
it('should add additional annotations to the controller constructor', function() {
10464+
it('should expose additional annotations on the directive definition object', function() {
1046510465
var myModule = angular.module('my', []).component('myComponent', {
1046610466
$canActivate: 'canActivate',
1046710467
$routeConfig: 'routeConfig',
1046810468
$customAnnotation: 'XXX'
1046910469
});
1047010470
module('my');
1047110471
inject(function(myComponentDirective) {
10472-
expect(myComponentDirective[0].controller).toEqual(jasmine.objectContaining({
10472+
expect(myComponentDirective[0]).toEqual(jasmine.objectContaining({
1047310473
$canActivate: 'canActivate',
1047410474
$routeConfig: 'routeConfig',
1047510475
$customAnnotation: 'XXX'
1047610476
}));
1047710477
});
1047810478
});
1047910479

10480+
it('should support custom annotations if the controller is named', function() {
10481+
var myModule = angular.module('my', []).component('myComponent', {
10482+
$customAnnotation: 'XXX',
10483+
controller: 'SomeNamedController'
10484+
});
10485+
module('my');
10486+
inject(function(myComponentDirective) {
10487+
expect(myComponentDirective[0]).toEqual(jasmine.objectContaining({
10488+
$customAnnotation: 'XXX'
10489+
}));
10490+
});
10491+
});
10492+
1048010493
it('should return ddo with reasonable defaults', function() {
1048110494
angular.module('my', []).component('myComponent', {});
1048210495
module('my');

0 commit comments

Comments
 (0)