I would like to use Angular 2 for the front end of an existing ASP.NET 4 app, i.e. not MVC 6/ASP.NET CORE, and I'd rather not use node as we are already using nuget as our package manager. Does anyone know of any resources that will guide me through this?
In this article, you will learn about AngularJS login form with ASP.NET. Learn to Create an empty MVC project, install Angular package, add Javascript Controllor, and add a Model class to the solution. As per you request, I am going to make a login page in AngularJS and ASP.
Asp.net MVC is used to develop applications that processes request at server. It also delivers view. But ultimately it renders the view at server and sends plain HTML to user. On the other hand, angular JS does not do any processing at server.
AngularJS With ASP.NET MVC. AngularJS is a JavaScript framework to create SPA (Single Page Application). It is a client side MV* (MVC+MVVM=MV*) framework. AngularJS extends HTML by providing Directives that add functionality to your markup and that allow you to create powerful dynamic templates for application. The following are some AngularJS...
Give your project and solution a name. When you get to the Additional information window, be sure to check the Add integration for Empty ASP.NET Web API Project option. This option adds files to your Angular template so that it can be hooked up later with the ASP.NET Core project.
As our planning, we are using AngularJS routing to create the Single Page Application by ASP.NET static file serving. We need to point a static page to get all the request then Angular will handle the request and decide which page to serve. Let's create html page in wwwroot folder.
Right-click the ASP.NET Core project and choose Properties. Go to the Debug menu and select Open debug launch profiles UI option. Uncheck the Launch Browser option. Next, right-click the Angular project and select the Properties menu and go the Debugging section. Change the Debugger to launch to the launch.json option.
To answer my original question, this is how we have managed to get Angular 2 up and running with .net 4.5.1 (we did end up having to use npm).
In the header of _Layout.cshtml, imported the Angular 2 files from the cdn and configured SystemJs.
<!-- 1. Load libraries -->
<!-- IE required polyfills, in this exact order -->
<script src="../../node_modules/es6-shim/es6-shim.min.js"></script>
<script src="../../node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="../../node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
<script src="../../node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="../../node_modules/systemjs/dist/system.src.js"></script>
<script src="../../node_modules/rxjs/bundles/Rx.js"></script>
<script src="../../node_modules/angular2/bundles/angular2.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script>
System.config({
packages: {
'my-app': {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('my-app/main')
.then(null, console.error.bind(console));
</script>
Added package.json and tsconfig.json to the route of the project
packages.json:
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings",
"postinstall": "typings install"
},
"license": "ISC",
"dependencies": {
"angular2": "2.0.0-beta.9",
"systemjs": "0.19.24",
"es6-promise": "^3.0.2",
"es6-shim": "^0.35.0",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"zone.js": "0.5.15"
},
"devDependencies": {
"typescript": "^1.8.7",
"typings": "^0.7.5"
}
}
tsconfig.json:
{
"compileOnSave": true,
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
If you have node and npm installed on your machine, it should automatically download the npm modules you need, and save them in the node_modules folder. You should now be ready to set up an Angular 2 application, we used the this to get started.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With