Search code examples
c#asp.netangulardotnet-sdk

How to add Angular support to C# Web Application?


I have an existing ASP.NET Web application that I am trying to add Angular views to. I found examples of how to start with a new project but not how to add it to an existing project.

Notes

  • .NetSDK 2.1
  • Visual Studio 2017
  • Everything is written in C# (and working), I am trying to add one Angular view as a proof of concept

Solution

  • Not sure I totally understand your issue, but that's how I do for my project. I have a .net mvc project that part of it (membership section) is using Angular. I add the Angular by these ways:

    1. create a separate Angular 6 project.
    2. Build the project by "ng build"
    3. In the "dist" folder these are four main Angular files: main.js, polyfills.js, runtime.js, style.css.
    4. Import those files into the ASP production project.
    5. In index.cshtml file, I use old school html js <script> tag and <style> and the most important Angular tag: <app-root></app-root>

    That's all you need for adding the Angular and everything works find. This may bing a issue when you need to make change to the Angular project then rebuild those files again and import them. But I can't find any tutorial can solve my needs so far. Some people may have a better solution.

    Addition: When you look into Angular builded index.html file, it does the same simple way and nothing complex in it.