填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫Home

NG8001: Unknown HTML element or component
未知的 HTML 元素或元件

說明

Description

在編譯期間無法解析一個或多個元素,因為該元素不是由 HTML 規範定義的,或者該元素選擇器不包含任何元件或指令。

One or more elements cannot be resolved during compilation because the element is not defined by the HTML spec, or there is no component or directive with such element selector.

這是常見執行時錯誤 NG0304: '${tagName}' is not a known element: … 的等價物。

This is the compiler equivalent of a common runtime error NG0304: '${tagName}' is not a known element: ….


如何排除本錯誤

Debugging the error

在錯誤中根據元素名稱來查詢正在使用該元素的檔案。

Use the element name in the error to find the file(s) where the element is being used.

檢查名稱和選擇器是否正確。如果該元件來自其他模組或匯入,請檢查該元件是否已從其原始模組中匯出並匯入到了正確的 *.modules.ts 檔案中,並已在匯入列表中宣告過。

Check that the name and selector are correct. If the component is from a different module or import, check that the component is exported from its origin module and imported into the correct *.modules.ts file, and declared in the imports list.

使用自訂元素或 Web 元件時,請確保將 CUSTOM_ELEMENTS_SCHEMA新增到 AppModule 中。

When using custom elements or web components, ensure that you add CUSTOM_ELEMENTS_SCHEMAto the app module.

如果還不能解決此錯誤,請檢查匯入的函式庫,以檢查對正在使用的匯出和屬性的任何最新更改,然後重新啟動伺服器。

If this does not resolve the error, check the imported libraries for any recent changes to the exports and properties you are using, and restart your server.