Fares Ayyad

Fares Ayyad

  • NA
  • 235
  • 74.3k

Integrating Asp.net Core 2.0 mvc project with Angular 4

Nov 24 2017 4:50 PM
Hello 
 
I'm trying to integrate asp.net core 2.0 with angular 4 project, i used this tutorial as a first step: 
https://medium.com/@levifuller/building-an-angular-application-with-asp-net-core-in-visual-studio-2017-visualized-f4b163830eaa
 
i feel like there's something missing by following the tutorial even though the application runs succesfully, but there's some strange errors appears in the console from angular side. 
 
now i wil explain how i create the project: 
the project is made with VS2017, .Net Core2.0 i used to create an MVC template.
then i follow the tutorial to add angular 4. 
 
By running ng build there's some scripts that has been generated, i include them in the _layout.cshtml file :
 
<script src="~/dist/inline.bundle.js"></script>
<script src="~/dist/polyfills.bundle.js"></script>
<script src="~/dist/styles.bundle.js"></script>
<script src="~/dist/vendor.bundle.js"></script>
<script src="~/dist/main.bundle.js"></script>
 
in the index.cshtml file in include angular tag: 
<app-root></app-root>
 
it worked fine, BUT when i navigate to another .cshtml page an error apperes in the console: 
The selector "app-root" did not match any elements 
 
 
and if i include another tag for another angular component: 
<app-post-list></app-post-list>
 
 
the error apperes again.
 
i don't know what's gone wrong.  
 

Answers (2)