简体   繁体   中英

How to fix this error The selector “app-component” did not match any elements in angular 2.0 application

I am getting an error in browser console when I click on the browser refresh button after running my Angular 2 application. It doesn't stop Angular 2 routing from one component to the other. Aside from the error it is working fine. But I want my app to run with 0 warnings or errors in the console .

This is the error I am getting in my browser console .

Error in ./t class t_Host - inline template:0:0 caused by: The selector "app-component" did not match any elements. ORIGINAL EXCEPTION: The selector "app-component" did not match any elements.

How can I clear this error ?

For me, the problem was that I was bootstrapping other components n AppModule. Only AppComponent needs to be bootstrapped. Remove all other declarations from the bootstrap array, so your @NgModule looks like this:

@NgModule({
  ...
  bootstrap:    [ AppComponent ],
  ...
})

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