ASP NET Core MVC API with Angular app not updating with my changes (beginner)

592 views
Skip to first unread message

Benjamin Charlton

unread,
Aug 25, 2017, 8:02:52 AM8/25/17
to Angular and AngularJS discussion

Hi there!


I'm an experienced C# developer but I'm really struggling to learn Angular4 and I'd really appreciate some help, please.


I'm using Visual Studio 2017 Community Edition to make an ASP NET Core MVC API application with an Angular4 front-end, starting from the out-of-the-box template that has a HomeComponent, CounterComponent and FetchDataComponent. I'm afraid I have broken something and I don't know how to fix it.


My trouble is that, when I debug the application from Visual Studio using Chrome browser, Angular seems to be ignoring any changes that I made to my source files - it's as if it's serving up the original template application instead of the one I edited. For example:


I changed "Hello, World!" to "Hello, Cruel World!" in my home.component.html and debug, but the change isn't reflected.

So then I tried changing app.routing.ts so that it should load a completely different component when the app is started. I changed:

    { path: '', component: HomeComponent }

To

    { path: '', component: CounterComponent }


But when I debug, it still loads the HomeComponent. Next I renamed HomeComponent to HoomeCompoonent so it should be 100% impossible for the app to work now. It should be totally broken but it isn't. It stubbornly loads the HomeComponent exactly the same as how it looked before I started. It's as if nothing I do makes a difference.

I have deleted the bin, and obj folders before rebuilding, in case Visual Studio was caching a previous version of the app, but it still serves the original Angular site instead of my updated one.


I have a suspicion that it's something to do with wwwroot. I guess maybe Visual Studio is supposed to update some files in wwwroot when the Angular app is changed, and maybe it isn't doing that?


I decided to do a search for the text "Hello, World" in my wwwroot folder and found it in a very long, complex file called main-client.js in wwwroot/dist I thought this could be the place where the old version is being cached. I deleted the file, and managed to break the site. I got an error in the Chrome developer window that it couldn't find the file.


Do I have to learn to edit the main-client.js file, or is that file supposed to be auto-generated by Visual Studio? How do I make the file update when I change my Angular components? Or am I on the wrong track completely?


Appreciate any advice. Thanks in advance!

Sander Elias

unread,
Aug 25, 2017, 8:10:51 AM8/25/17
to Angular and AngularJS discussion
Hi Benjamin.

I never liked IDE's so I have no experience with visual studio. So i might be off 200%. but it sound like the build step isn't done. If you have generated the app with the angular-cli that would be ng build, but i have no idea how/or this translates to VS.

Regards
Sander

Benjamin Charlton

unread,
Aug 25, 2017, 8:34:20 AM8/25/17
to Angular and AngularJS discussion
Thank you very much for your interest and suggestion, Sander.
So, to identify this is the case, I guess I should try to do that ng build command from the windows command prompt, right?
What directory should I be in when I try the command? The wwwroot directory? Or the ClientApp directory? Or maybe the parent directory to both of those, where my package.json and tsconfig.json files reside?
Reply all
Reply to author
Forward
0 new messages