Skip to content

Commit 90975db

Browse files
feat($compileProvider): allow component() helper to copy over custom annotations
Closes angular#13741
1 parent 25bc531 commit 90975db

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/ng/compile.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
968968
* See {@link ng.$compile#-bindtocontroller- `bindToController`}.
969969
* - `transclude` – `{boolean=}` – whether {@link $compile#transclusion content transclusion} is enabled.
970970
* Disabled by default.
971-
* - `$canActivate` – `{function()=}` – TBD.
972-
* - `$routeConfig` – `{object=}` – TBD.
971+
* - `$...` – `{function()=}` – additional annotations to provide to the directive factory function.
973972
*
974973
* @returns {ng.$compileProvider} the compile provider itself, for chaining of function calls.
975974
* @description
@@ -1080,12 +1079,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
10801079
};
10811080
}
10821081

1083-
if (options.$canActivate) {
1084-
factory.$canActivate = options.$canActivate;
1085-
}
1086-
if (options.$routeConfig) {
1087-
factory.$routeConfig = options.$routeConfig;
1088-
}
1082+
// Copy any annotation properties (starting with $) over to the factory function
1083+
// These could be used by libraries such as the new component router
1084+
forEach(options, function(val, key) {
1085+
if (key.charAt(0) === '$') {
1086+
factory[key] = val;
1087+
}
1088+
});
1089+
10891090
factory.$inject = ['$injector'];
10901091

10911092
return this.directive(name, factory);

test/ng/compileSpec.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -9321,14 +9321,16 @@ describe('$compile', function() {
93219321
});
93229322
});
93239323

9324-
it('should add router annotations to directive factory', function() {
9324+
it('should add additional annotations to directive factory', function() {
93259325
var myModule = angular.module('my', []).component('myComponent', {
93269326
$canActivate: 'canActivate',
9327-
$routeConfig: 'routeConfig'
9327+
$routeConfig: 'routeConfig',
9328+
$customAnnotation: 'XXX'
93289329
});
93299330
expect(myModule._invokeQueue.pop().pop()[1]).toEqual(jasmine.objectContaining({
93309331
$canActivate: 'canActivate',
9331-
$routeConfig: 'routeConfig'
9332+
$routeConfig: 'routeConfig',
9333+
$customAnnotation: 'XXX'
93329334
}));
93339335
});
93349336

0 commit comments

Comments
 (0)