填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

NG0300: Multiple components match with the same tagname
多个组件都能匹配同一个标签名

说明

Description

两个或更多组件使用了相同的元素选择器。因为只能有一个与特定元素关联的组件,所以选择器必须是唯一的字符串,以防止 Angular 产生歧义。

Two or more components use the same element selector. Because there can only be a single component associated with an element, selectors must be unique strings to prevent ambiguity for Angular.


如何排除本错误

Debugging the error

使用错误消息中给出的元素名称在代码库中搜索使用相同选择器声明的位置:

Use the element name from the error message to search for places where you’re using the same selector declaration in your codebase:

      
      @Component({
  selector: 'YOUR_STRING',
  ...
})
    

确保每个组件都有一个唯一的 CSS 选择器。这将确保 Angular 渲染你所期望的组件。

Ensure that each component has a unique CSS selector. This will guarantee that Angular renders the component you expect.

如果使用此选择器标签名查找重复组件时遇到了问题,请检查导入的组件库中的组件,例如 Angular Material。确保你遵循了选择器的最佳实践,以防止发生冲突。

If you’re having trouble finding multiple components with this selector tag name, check for components from imported component libraries, such as Angular Material. Make sure you're following the best practices for your selectors to prevent collisions.