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

Commit 5cf9d03

Browse files
feat($compileProvider): allow component() helper to copy over custom annotations
1 parent 0137f47 commit 5cf9d03

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/ng/compile.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,12 +1079,15 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
10791079
};
10801080
}
10811081

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

10901093
return this.directive(name, factory);

test/ng/compileSpec.js

Lines changed: 5 additions & 3 deletions
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)