question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular RC.5 More than one component

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior In angular rc.5 you can`t have multiple components with same selector, which was in previous versions working without any problem. In rc.5 you have single “context” in which are all directives stored for whole module. Previously if i added some component to @Component directives array it was processed only in template of that component. Now it adds this component to some shared directives array for whole module.

By the way, this could be considered breaking change but it is not mentioned anywhere in changelog.

Expected/desired behavior

I would expected similar behaviour as for providers. Components added to ngModule.declaration will be available in templates of all components. Components added to component.directives will override ngModule.declaration and will be available only in template of this component.

I know that probably solution would be use modules, but create module which will contain only 1 component is bad usage of ngModule. Since i have 6 components and 2 html files which are shared by 3 of them i would have to create 6 modules which is crazy.

Reproduction of the problem Here is plunker showing problem https://plnkr.co/edit/u3ergwERz0vfsVmH0Fcb?p=preview Exactly same code would in rc.4 work without any problem. In rc.5 it is not working.

What is the motivation / use case for changing the behavior?

I need this because i have one html file for multiple components, which share same public interface but different “components” are injected into directives array. So single html can display different components.

This way i have to have 3 almost same html files (except one element).

Please tell us about your environment:

  • Angular version: 2.0.0-rc.5
  • Browser: [all]
  • Language: [TypeScript 1.8.10]

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:10
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
awilhelmercommented, Aug 10, 2016

I’ve got the same Problem. I used the selectors to have multiple components in the main app.component. The reason I did it like that was having a global template HTML. In RC.4 it was done easily in the app.component.html (Many Tags for selectors to have a central design template…)

It’s a show-stopper for me, I don’t know how to maintain a global HTML template. I have to repeat design things in each component.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 9, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Switching to RC5: more than one component - Stack Overflow
To solve the "more than one component" error, like @rashfmnb suggests, (1) remove all double @Component decorators (not in my case) and (2) ......
Read more >
NG0300: Multiple components match with the same tagname
Two or more components use the same element selector. Because there can only be a single component associated with an element, selectors must...
Read more >
Angular components overview
Components are the main building block for Angular applications. Each component consists of: An HTML template that declares what renders on the page ......
Read more >
Getting started with standalone components - Angular
Standalone components provide a simplified way to build Angular applications. Standalone components, directives, and pipes aim to streamline the authoring ...
Read more >
Create a feature component - Angular
At the moment, the HeroesComponent displays both the list of heroes and the selected hero's details. Keeping all features in one component as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found