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

前端 未结 12 1125
逝去的感伤
逝去的感伤 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条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 18:58

    I was updating an Angular 5.2 app to Angular 6.1 and run into similar issue. In this case the problem was that index.html file did not have at all. It was instead included in the my-app component.

    
    
    
      
      Example
      
      
      
    
    
    
    

    This used to work with Angular 5.2 (and earlier versions too) because in the generated index.html the script tags were placed at the end. After upgrade to 6.1 the script tags were instead placed in the beginning of the file (and I assume therefore executed before the root element is actually present.

    Solution was to move into index.html. (It was originally placed in to the component because someone wanted to apply conditional classes to body element with ngClass.)

提交回复
热议问题