填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫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.