简体   繁体   中英

Angular 5: ERROR Error: The selector “app-root” did not match any elements

I've checked and compiled 12 times now and can't seem to figure out why I'm getting this error in my console:

ERROR Error: The selector "app-root" did not match any elements
at e.selectRootElement (main.bundle.js:1)
at Sn (main.bundle.js:1)
at zr (main.bundle.js:1)
at Lr (main.bundle.js:1)
at Object.io [as createRootView] (main.bundle.js:1)
at t.create (main.bundle.js:1)
at t.create (main.bundle.js:1)
at e.bootstrap (main.bundle.js:1)
at main.bundle.js:1
at Array.forEach (<anonymous>)

Index.html

<body>
  <app-root></app-root>
</body>

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
        HttpModule
      ],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'App Component';
}

I've read through several others who experienced this error and it was usually due to the index.html file not using the correct selector name. I've checked my code and it looks correct to me.

添加了一个工作plunker ,从 4.3.x HttpModule 可作为 HttpClientModule 在'@angular/common/http'

Make sure you have added app-root in index.html

<body>

<app-root></app-root>

</body>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM