Multiple components match node with tagname app-lobby

后端 未结 7 1136
刺人心
刺人心 2021-02-14 05:51

the code was running fine on angular version 8.3.4 but when i updated it to the latest version of angular ( 9 ) i got the following error

following is t

相关标签:
7条回答
  • 2021-02-14 06:17

    The two answers above about declaring DatePipe in providers should be considered. Today I met this problem (Angular 9) when adding an argument private datePipe: DatePipe in the constructor of my component without declaring DatePipe in the module's provider. After adding DatePipe in providers, I have no more the problem.

    The constructor :

    constructor(private authenticationService: AuthenticationService, private datePipe: DatePipe) {}
    
    0 讨论(0)
  • 2021-02-14 06:18

    @VikasBhardwaj I had same problem in Angular 9 because I have created lobby page and lobby component. In this case, app-lobby is duplicated in pages and components.

    @Component({
      selector: 'app-feed',
    

    So I have changed page name as lobbies, so the problem is fixed.

    0 讨论(0)
  • 2021-02-14 06:19

    Probably you have more than one component with the same selector tag name app-lobby

    ...
    @Component({
       selector: 'app-lobby',
    ...
    

    Please double check to ensure that only one component selector tag name is app-lobby.

    0 讨论(0)
  • 2021-02-14 06:32

    I have an app in angular 9. I had similar problem, but then i realised that i forgot the provider for DatePipe. After that, this error went away... Maybe errors like these won't be happening after some time of angular 9 development.

    0 讨论(0)
  • 2021-02-14 06:38

    This error actually has less to do with the tagname app-lobby. I encountered this error when I applied multiple component selector on a html tag.

    For example: Component 1

    @Component({
        ...
        selector: '[my-tooltip]',
        ...
    })
    

    Component 2

    @Component({
        ...
        selector: '[my-button]',
        ...
    })
    

    Notice that both of them are angular component yet having a selector like attribute directive.

    When you apply both of them on the same tag like below:

    <button my-button my-tooltip="Some tooltip">Hover me</button>
    

    Then angular complains about applying 2 components on a single tag. In this case it will complain about button tag, like: Error: Multiple components match node with tagname button

    The solution would be not to use multiple component selector on a single element.

    0 讨论(0)
  • 2021-02-14 06:41

    Add DatePipe in the providers.It will work fine.

    0 讨论(0)
提交回复
热议问题