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

Commit

Permalink
feat($compileProvider): allow component() helper to copy over custo…
Browse files Browse the repository at this point in the history
…m annotations

Closes #13741
  • Loading branch information
petebacondarwin committed Jan 12, 2016
1 parent 25bc531 commit 90975db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
17 changes: 9 additions & 8 deletions src/ng/compile.js
Expand Up @@ -968,8 +968,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
* See {@link ng.$compile#-bindtocontroller- `bindToController`}.
* - `transclude` – `{boolean=}` – whether {@link $compile#transclusion content transclusion} is enabled.
* Disabled by default.
* - `$canActivate` – `{function()=}` – TBD.
* - `$routeConfig` – `{object=}` – TBD.
* - `$...` – `{function()=}` – additional annotations to provide to the directive factory function.
*
* @returns {ng.$compileProvider} the compile provider itself, for chaining of function calls.
* @description
Expand Down Expand Up @@ -1080,12 +1079,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
};
}

if (options.$canActivate) {
factory.$canActivate = options.$canActivate;
}
if (options.$routeConfig) {
factory.$routeConfig = options.$routeConfig;
}
// Copy any annotation properties (starting with $) over to the factory function
// These could be used by libraries such as the new component router
forEach(options, function(val, key) {
if (key.charAt(0) === '$') {
factory[key] = val;
}
});

factory.$inject = ['$injector'];

return this.directive(name, factory);
Expand Down
8 changes: 5 additions & 3 deletions test/ng/compileSpec.js
Expand Up @@ -9321,14 +9321,16 @@ describe('$compile', function() {
});
});

it('should add router annotations to directive factory', function() {
it('should add additional annotations to directive factory', function() {
var myModule = angular.module('my', []).component('myComponent', {
$canActivate: 'canActivate',
$routeConfig: 'routeConfig'
$routeConfig: 'routeConfig',
$customAnnotation: 'XXX'
});
expect(myModule._invokeQueue.pop().pop()[1]).toEqual(jasmine.objectContaining({
$canActivate: 'canActivate',
$routeConfig: 'routeConfig'
$routeConfig: 'routeConfig',
$customAnnotation: 'XXX'
}));
});

Expand Down

0 comments on commit 90975db

Please sign in to comment.