我想使用Angular 2作为现有的ASP.NET 4应用的前端,也就是说,不是MVC6/ASP.Net核心,我不想使用node,因为我们已经使用nuget作为包管理器了。有没有人知道有什么资源可以指导我完成这件事?
发布于 2016-03-29 21:55:44
为了回答我最初的问题,这就是我们如何在.net 4.5.1上启动并运行Angular 2(我们最终不得不使用npm)。
在_Layout.cshtml的header中,从cdn导入Angular 2文件,并配置了SystemJ。
<!-- 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>
在工程路由中添加package.json和tsconfig.json
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"
]
}
如果您的机器上安装了node和npm,它应该会自动下载您需要的npm模块,并将它们保存在node_modules文件夹中。您现在应该已经准备好设置Angular 2应用程序了,我们使用this开始。
发布于 2016-08-08 22:38:53
他们已经用一个非核心方案更新了Angular站点:
https://angular.io/docs/ts/latest/cookbook/visual-studio-2015.html
发布于 2016-09-16 22:48:10
我已经为Angular 2.0创建了一个启动项目,它刚刚在https://github.com/chanoto89/angular2-startup上与ASP.NET 4.5.2一起上线。
我使用了http://blogs.msmvps.com/deborahk/angular-2-getting-started-with-a-visual-studio-2015-asp-net-4-x-project/大纲,但利用了MVC和gulp在项目中移动所需依赖项的优势,而不是使用npm安装的整个node_modules。
https://stackoverflow.com/questions/35990812
复制相似问题