The selector “my-app” did not match any elements

前端 未结 12 1134
逝去的感伤
逝去的感伤 2020-12-07 18:15

The problem is when I run my app, it works fine. But when I refresh it, most of the time I get below msg.

The selector \"my-app\" did not match any e

12条回答
  •  萌比男神i
    2020-12-07 19:00

    This happened to me because I was importing my code in the head tag, so it was potentially running and attempting to bootstrap before the DOM was ready.

    You can either move the script to the bottom of the body tag, or put the bootstrap code within an event listener:

    document.addEventListener("DOMContentLoaded", function(event) {
      bootstrap(AppComponent);
    });
    

    or:

    
    
      
        
        Example app
      
      
        
      
      
    
    

提交回复
热议问题