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

feat($compile): add custom annotations to the controller #14114

Conversation

petebacondarwin
Copy link
Contributor

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    feat
  • What is the current behavior? (You can also link to an open issue here)
    inconvenient
  • What is the new behavior (if this is a feature change)?
    add custom annotations to the controller of component directives
  • Does this PR introduce a breaking change?
    Nope
  • Please check if the PR fulfills these requirements
  • The commit message follows our guidelines: https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#commit-message-format
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Other information:

This means that we can access these annotations, such as
$routeConfig and $routerCanActivate without highjacking
the ng module.

This means that we can access these annotations, such as
`$routeConfig` and `$routerCanActivate` without highjacking
the `ng` module.
@Narretz
Copy link
Contributor

Narretz commented Feb 23, 2016

LGTM. What is the router doing with these annotations?

@petebacondarwin
Copy link
Contributor Author

The router needs to extract this metadata. Previously, the annotations were added to the factory function, but this meant that we had to intercept calls to module.directive. With this change, we can use the $injector to get the controller constructor and then access the annotations that way.

@petebacondarwin
Copy link
Contributor Author

And it allows us to get rid of a load of horrible router code. See petebacondarwin/ng1-component-router-demo@eb960ee

@petebacondarwin
Copy link
Contributor Author

Landed with an update to the docs for the component() helper function.

petebacondarwin added a commit that referenced this pull request Feb 23, 2016
This means that we can access these annotations, such as
`$routeConfig` and `$routerCanActivate` without highjacking
the `ng` module.

Closes #14114
@gseabrook
Copy link

I'm interested to know if I am configuring my components incorrectly as this change broke my app. My component config looks like

angular
        .module('menu')
        .component('menu', {
            controller: 'MenuController',
            templateUrl: './components/menu/menu.html',
            $canActivate: function() {
                return true; //real code omitted for brevity
            }
        });

However when "controller[key]" = val runs on line 1109 the controller variable is a string and so it fails

@petebacondarwin
Copy link
Contributor Author

Ahah! Good catch! That is a bug.

@petebacondarwin petebacondarwin deleted the component-custom-annotations branch November 24, 2016 09:21
@petebacondarwin petebacondarwin restored the component-custom-annotations branch November 24, 2016 09:21
@petebacondarwin petebacondarwin deleted the component-custom-annotations branch November 24, 2016 09:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants