I just did this with Angular 5 and MVC 5. I suggest you get a "Hello World" working first, and then port it into your existing MVC problem.
Pre-reqs - make sure you have the latest Node, NPM, AngularCLI installed...
In VS2017, create a New ASP.NET Web Application, SPA with MVC and WebAPI 1.1. Show all files (in the Solution Explorer - this makes things easier!)
From the package manager console uninstall unneeded packages:
UnInstall-Package Sammy.js
UnInstall-Package Bootstrap
UnInstall-Package JQuery
UnInstall-Package Knockout.validation
UnInstall-Package Knockoutjs
UnInstall-Package modernizr
UnInstall-Package Microsoft.ApplicationInsights.Web -RemoveDependencies
Remove all bundles in BundleConfig.cs (we'll pull them in later!)
Delete Scripts folder (it will be recreated using the AngularCLI)
Add Angular using CLI (go into the project root folder)
Run: ng new Scripts --skip-tests --style scss
In the Project, Include all folders EXCEPT node_modules!
Update angular.json to output to a Bundles folder -> "outputPath": "../Bundles"
Add bundles:
bundles.Add(new ScriptBundle("~/Script/Bundles")
.Include("~/bundles/inline.*", "~/bundles/polyfills.*",
"~/bundles/scripts.*", "~/bundles/vendor.*", "~/bundles/runtime.*",
"~/bundles/main.*"));
bundles.Add(new StyleBundle("~/Content/Styles") .Include("~/bundles/styles.*"));
(Optional) Re-add libraries through NPM (command prompt from Scripts folder):
npm install jquery --save
npm install popper.js --save
npm install bootstrap --save
(Optional) Reference them in angular.json so AngularCLI pulls them into the webpack bundles:
"styles": [
"src/styles.scss",
"./node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [
"./node_modules/jquery/dist/jquery.min.js",
"./node_modules/popper.js/dist/umd/popper.min.js",
"./node_modules/bootstrap/dist/js/bootstrap.min.js"
]
Build from scripts folder: ng build --extractCss
In _Layout.cshtml, add:
@Styles.Render("~/Content/Styles") <!-- In the "head" element -->
and
@Scripts.Render("~/Script/Bundles") <!-- At the end of the "body" element -->
Remove the old bundle imports!
In Home/Index.cshtml, add the Angular element:
<app-root>test</app-root>
13.1 Remove the old bundle imports!
Run the web app - it should open up. Register a new user, and then login. Show the MVC5 demo page together with the Angular
To "watch" the webpage - from the command line:
ng build --extractCss --watch
This will rebuild the Bundles. Unfortunately you need to refresh the browser, but this is better than stop/starting things!
Shout if you need more detail - I've run through this twice to get familiar with it, and it works nicely!