2

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?

wuno
  • 9,547
  • 19
  • 96
  • 180
Vinod
  • 1,234
  • 3
  • 21
  • 37
  • 1
    Does this error only appear when you refresh the screen after the app is running fine? – wuno Dec 02 '16 at 07:10
  • it looks like you used tag some where in your template but your component does not have the selector 'app-component'. check that your AppComponent have selector named properly. – mehari Dec 02 '16 at 07:11
  • @wuno, yes i mean to say its intermittently occurs, and if i again click on refresh button its run the application without any error in console. – Vinod Dec 02 '16 at 07:46
  • @Mehari, no i used only in index.html and in app.component.ts have selector as a 'selector: 'app-component' – Vinod Dec 02 '16 at 07:52
  • Oh wait I think I misunderstood you. So you are not getting errors when you refresh the page? You mean in the console it has an error and thats it? Not a 404? or the content not loading in the page when you refresh it the first time? – wuno Dec 02 '16 at 08:16
  • @VinodPharande is my answer does not help you I strongly suggest you add a lot more information about your program. Your question is basically just showing an error and saying how do I fix this. That is typically pretty close to impossible for anyone to actually answer without seeing at least a small portion of your code. Also it would be nice to know what your using in your application. For example the back end etc. I would be surprised if you are only using angular2 which is all we can gather at this point from your question. – wuno Dec 02 '16 at 08:29
  • @wuno, when i refresh the page then i am getting this error (its not happened in specific time that means some time while refreshing first time and some times even if i tried multiple time refresh then this error comes in console), but not always its an intermittent error, after this if i clicked on browser refresh button again then its working fine. so its not about 404. – Vinod Dec 02 '16 at 10:11
  • @wuno, fornt end: Angular 2.0+typescipt, back end: node.js with express js. For template/view engine for nods js we used ejs(Embedded JavaScript templates) and code is, app.set('view engine', 'ejs'); – Vinod Dec 02 '16 at 10:39

1 Answers1

0

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 ],
  ...
})
anonym
  • 4,460
  • 12
  • 45
  • 75