首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >AngularJs 2,带ASP .NET 4.5.1

AngularJs 2,带ASP .NET 4.5.1
EN

Stack Overflow用户
提问于 2016-03-14 22:52:56
回答 4查看 20.4K关注 0票数 16

我想使用Angular 2作为现有的ASP.NET 4应用的前端,也就是说,不是MVC6/ASP.Net核心,我不想使用node,因为我们已经使用nuget作为包管理器了。有没有人知道有什么资源可以指导我完成这件事?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-03-29 21:55:44

为了回答我最初的问题,这就是我们如何在.net 4.5.1上启动并运行Angular 2(我们最终不得不使用npm)。

在_Layout.cshtml的header中,从cdn导入Angular 2文件,并配置了SystemJ。

代码语言:javascript
复制
<!-- 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:

代码语言:javascript
复制
{
 "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:

代码语言:javascript
复制
{
 "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开始。

票数 19
EN

Stack Overflow用户

发布于 2016-08-08 22:38:53

他们已经用一个非核心方案更新了Angular站点:

https://angular.io/docs/ts/latest/cookbook/visual-studio-2015.html

票数 2
EN

Stack Overflow用户

发布于 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。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35990812

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档