錯誤百科

找不到根元素

啟動的元件定義在 @NgModule 裝飾器的 bootstrap 屬性中,或是獨立元件的 bootstrapApplication 的第一個參數。

當 Angular 嘗試啟動這些元件之一,卻在 DOM 中找不到其對應的節點時,就會發生此錯誤。

除錯方式

當選擇器與標籤不相符時,就會發生此問題

@Component({
  selector: 'my-app',
  ...
})
export class App {}
<html>
  <app-root></app-root> <!-- Doesn't match the selector -->
</html>

把標籤換成正確的標籤:

<html>
  <my-app></my-app> <!-- OK -->
</html>