Closed Xoadra closed 6 years ago
Hi Ian, sorry didn't get to your issue earlier; would I be correct in assuming you are using ng to serve up your site from "ng serve --port 5000" below ... hence the line in error saying: Evaluating http://localhost:5000/wwwroot/app
this project instead needs to be served through Kestrel or IIS/PWS. I'm making use of the ASP.Net Core templates with some modifications to serve the angular SPA. I have kept many of the page names, just for familiarity.
index.html is a hangover from the original ng code, the work it does in a flat-file based traditional setup gets split between index.cshtml, app.cshtml and_layout.cshtml- this allows server side code to be executed and served up to the client.
Have a look in the branch Angular5 https://github.com/RobertDyball/A2SPA/tree/Angular5 as this is using Angular 5.2.x and .Net core 2.x
or a more recent version (a bit rough) where I'm switching to ngx-bootstrap, the branch is here: https://github.com/RobertDyball/A2SPA/tree/ngx-bootstrap
If I have this wrong, please PM me a zipped up copy of your code, you can reach me at robert.dyball at gmail dot com
No problem!
I'm actually not, since running my dotnet server also uses that port so it wouldn't work. I did try serving it up from its default port at 4200 but unsurprisingly that didn't work either. Then again I don't know if that means of linking the two separate frameworks would be a wise or even workable solution when it comes time for production and deployment.
So I did notice you had settings in some projects whereby you had additional settings configured in your Program.cs
and Startup.cs
files. I've given those a shot as well but I was still unable to get the original AppComponent template app.component.html
to appear. I will take a loot at some of the earlier commits in both of those branches to see if any of the solutions there resolve the issue I'm currently wrestling with.
I'll also send you a copy of my most up-to-date version so hopefully that helps!
Hi Ian,
Got it working, the error you had originally was because the app component being fetched was actually a default HTML page, not being a partial component, but tags etc.
Next looked at how the code was set up (and forgetting you’d simply started at part 1) I replaced out the index.html (as a default it stops index.cshtml getting a look in), then moved the contents of index.cshtml, the partial shared layout file _Layout.cshtml and realized there was no view controller there yet to serve up server side .cshtml as partials. (probably me skipping to part 2or 4 or something ..again sorry much of my dev time = commute time = little or not internet access) perils of mountains, tunnels and lazy telcos.).
Anyway added a partial controller, moved the mvc views that would become angular templates (partial views) into a partial directory to get served up by the partial controller.
Edited the angular component (added a couple of extra ones) to point to the partial mvc views and not flat html as it was.
Had to alter systemconfig.js to pick up the umd bundles, along the way disabled environment.ts (sorry for you to fix again now 😊 ), and added some missing scripts to the script block in _Layout.cshtml
Lastly moved the asp.netcore tag helper version of the bootstrap nav/menu to app.component.cshtml, and added angular routing in .
Now index.cshtml loads app component, and the router tag there is where angular then loads the partials.
When I get home I’ll zip up the source and get back to you.
My original issue was ultimately resolved so I suppose there's no reason to keep this up anymore. Thanks for your help!
I'm working with a cli-generated project for both the ASP.NET Core and Angular parts using Visual Studio Code, so in essence I'm retracing the steps you originally took in your part 1 tutorial but within VSCode instead and with the current versions of ASP.NET Core (2.0.0) and Angular (5.2.2). However, I've consistently ran into the same issue even after trying and testing with older versions to retrace the steps you took in your tutorial.
While I've been successfully able to display ASP.NET Core pages from both the root route (prior to overriding it) and
/home/index
and the Angularindex.html
page from the root route (after overriding ASP.NET Core) and/index.html
, I cannot get the AppComponent template to display as you do in your tutorial, only the loader text still.My errors have been pretty consistent despite making a variety of edits to try and diagnose the issue, but my primary error is
Unhandled Promise rejection: Unexpected token <
. In full, I get:Now, I am aware that ultimately you end up resorting to using ASP.NET Core templates instead for the SPA behavior and Angular integration, but I'm concerned that it may still be important to get this kind of project to work down the line, especially considering that you're still using those SystemJS files despite no longer having an
index.html
file.For reference, here are some of the relevent files in my project:
Hopefully that includes everything you might need from me. Let me know if there's anything else you need to take a look at.