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

Commit 7e112c1

Browse files
feat($compile): add custom annotations to the controller
This means that we can access these annotations, such as `$routeConfig` and `$routerCanActivate` without highjacking the `ng` module. Closes #14114
1 parent 59aef48 commit 7e112c1

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/ng/compile.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
10301030
* See {@link ng.$compile#-bindtocontroller- `bindToController`}.
10311031
* - `transclude` – `{boolean=}` – whether {@link $compile#transclusion content transclusion} is enabled.
10321032
* Disabled by default.
1033-
* - `$...` – `{function()=}` – additional annotations to provide to the directive factory function.
1033+
* - `$...` – additional properties to attach to the directive factory function and the controller
1034+
* constructor function. (This is used by the component router to annotate)
10341035
*
10351036
* @returns {ng.$compileProvider} the compile provider itself, for chaining of function calls.
10361037
* @description
@@ -1106,6 +1107,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
11061107
forEach(options, function(val, key) {
11071108
if (key.charAt(0) === '$') {
11081109
factory[key] = val;
1110+
controller[key] = val;
11091111
}
11101112
});
11111113

test/ng/compileSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -10044,6 +10044,22 @@ describe('$compile', function() {
1004410044
}));
1004510045
});
1004610046

10047+
it('should add additional annotations to the controller constructor', function() {
10048+
var myModule = angular.module('my', []).component('myComponent', {
10049+
$canActivate: 'canActivate',
10050+
$routeConfig: 'routeConfig',
10051+
$customAnnotation: 'XXX'
10052+
});
10053+
module('my');
10054+
inject(function(myComponentDirective) {
10055+
expect(myComponentDirective[0].controller).toEqual(jasmine.objectContaining({
10056+
$canActivate: 'canActivate',
10057+
$routeConfig: 'routeConfig',
10058+
$customAnnotation: 'XXX'
10059+
}));
10060+
});
10061+
});
10062+
1004710063
it('should return ddo with reasonable defaults', function() {
1004810064
angular.module('my', []).component('myComponent', {});
1004910065
module('my');

0 commit comments

Comments
 (0)