Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor function syntax not working for non-bootstrap components #10545

Closed
filipesilva opened this issue Aug 6, 2016 · 4 comments · Fixed by #11043
Closed

Constructor function syntax not working for non-bootstrap components #10545

filipesilva opened this issue Aug 6, 2016 · 4 comments · Fixed by #11043
Assignees
Milestone

Comments

@filipesilva
Copy link
Contributor

I'm submitting a ... (check one with "x")

[x] bug report

Current behavior

When adding a component to the NgModule declaration array, if that component's constructor is a function (constructor: function() {}), the component is not added to the module.

Everything is fine if the array notation for the constructor is used though (constructor: [function() {}]).

Expected/desired behavior
Using a function as a constructor should be supported.

Reproduction of the problem
http://plnkr.co/edit/kuz9JlBLWUXaUDWtCn0s?p=preview (edited)
The only difference between HeroComponent and VillainComponent is how the constructors are declared, but HeroComponent does not show.

What is the motivation / use case for changing the behavior?
A function was a supported way of declaring a component constructor in RC4, and it still works for bootstrap components.

Please tell us about your environment:

  • Angular version: 2.0.0-rc.5
  • Browser: Chrome 52
  • Language: ES5
@naomiblack naomiblack added this to the 2.0.0-rc.6 milestone Aug 10, 2016
@wardbell
Copy link
Contributor

To be clear, this is for apps written in JS using the DSL not TS, right?

@filipesilva
Copy link
Contributor Author

@wardbell correct.

@chuckjaz chuckjaz self-assigned this Aug 23, 2016
@chuckjaz
Copy link
Contributor

chuckjaz commented Aug 23, 2016

A temporary work-around for this is to give the constructor function a name. For example, changing hero.component.js to:

(function(app) {
  app.HeroComponent =
    ng.core.Component({
      selector: 'my-hero',
      template: 'Harry McHeroface'
    })
    .Class({
      constructor: function HeroComponent() {}
    });
})(window.app || (window.app = {}));

is a work-around for this issue. The name doesn't have to match the name of the component but the generated code is easier to grok if it is.

chuckjaz added a commit to chuckjaz/angular that referenced this issue Aug 24, 2016
chuckjaz added a commit to chuckjaz/angular that referenced this issue Aug 24, 2016
chuckjaz added a commit to chuckjaz/angular that referenced this issue Aug 24, 2016
chuckjaz added a commit to chuckjaz/angular that referenced this issue Aug 24, 2016
chuckjaz added a commit to chuckjaz/angular that referenced this issue Aug 27, 2016
chuckjaz added a commit to chuckjaz/angular that referenced this issue Aug 27, 2016
tbosch pushed a commit to tbosch/angular that referenced this issue Aug 29, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants