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

Commit e366bfc

Browse files
feat($compile): put custom annotations on DDO
1 parent d279545 commit e366bfc

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/ng/compile.js

+11-1
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,8 +1117,18 @@ 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

1129+
// TODO(pete) remove the following `forEach` before we release 1.6.0
1130+
// when the router no longer looks for the annotations on the controller
1131+
11221132
// Copy any annotation properties (starting with $) over to the factory function
11231133
// These could be used by libraries such as the new component router
11241134
forEach(options, function(val, key) {

test/ng/compileSpec.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -10493,15 +10493,15 @@ describe('$compile', function() {
1049310493
}));
1049410494
});
1049510495

10496-
it('should add additional annotations to the controller constructor', function() {
10496+
it('should expose additional annotations on the directive definition object', function() {
1049710497
var myModule = angular.module('my', []).component('myComponent', {
1049810498
$canActivate: 'canActivate',
1049910499
$routeConfig: 'routeConfig',
1050010500
$customAnnotation: 'XXX'
1050110501
});
1050210502
module('my');
1050310503
inject(function(myComponentDirective) {
10504-
expect(myComponentDirective[0].controller).toEqual(jasmine.objectContaining({
10504+
expect(myComponentDirective[0]).toEqual(jasmine.objectContaining({
1050510505
$canActivate: 'canActivate',
1050610506
$routeConfig: 'routeConfig',
1050710507
$customAnnotation: 'XXX'
@@ -10515,9 +10515,11 @@ describe('$compile', function() {
1051510515
controller: 'SomeNamedController'
1051610516
});
1051710517
module('my');
10518-
expect(function() {
10519-
inject(function(myComponentDirective) {});
10520-
}).not.toThrow();
10518+
inject(function(myComponentDirective) {
10519+
expect(myComponentDirective[0]).toEqual(jasmine.objectContaining({
10520+
$customAnnotation: 'XXX'
10521+
}));
10522+
});
1052110523
});
1052210524

1052310525
it('should return ddo with reasonable defaults', function() {

0 commit comments

Comments
 (0)