Search code examples
angularangular-module

Angular 11 template parse errors : not a known element


As title,I'm trying to use another same level component in current component,but facing this errors.

DevTools gave me two solutions

  • If 'message-block' is an Angular component,then vertify that it is part of this module.
  • If 'message-block' is a Web component,then add 'CUSTOM_ELEMENT_SCHEMA' to the '@NgModule.schema' of this component to suppress this message.

Folder

  • block
    • customerProfile
      • profileBlock
        • profileInfo
          • profileInfo.html
          • profileInfo.ts
        • profileBlock.module.ts
    • message-block
  • block.modules.ts

Modules

Here is my block module

@NgModel({
  imports:[...otherModule],
  declarations:[messageBlockComponents],
  export:[messageBlockComponents]
})

  • I've check the message-block component's selector name is right
<message-block></message-block>

The errors is happening in profileInfo.html.I have declare message-block in block moodule,and it's a parent module,so I don't add any declartion in profileBlock.modules.

Question

How do I add message-block into profileInfo component?


Solution

  • Reason

    The reason that cause this error is that same layer component cannot identify each other,unless they have their own module to manage themself.

    Solution

    so I create a module for message-block.Let the block.module and profileBlock.module both import message-block module.