简体   繁体   English

如何为ASP.NET MVC设置Angular2?

[英]How to setup Angular2 for asp.net mvc?

angular.io has a setup for asp.net core: https://angular.io/docs/ts/latest/cookbook/visual-studio-2015.html . angular.io具有用于asp.net核心的设置: https ://angular.io/docs/ts/latest/cookbook/visual-studio-2015.html。

However, I'd like to set it up for an asp.net mvc app. 但是,我想将其设置为一个asp.net mvc应用程序。 The Quick Start files are already there from the asp.net mvc template. 快速启动文件已经在asp.net mvc模板中。 These are the ones from the site: 这些是网站上的:

app folder 应用文件夹
styles.css styles.css
index.html index.html
package.json package.json
tsconfig.json tsconfig.json

The contents of mine look exactly the same. 我的内容看起来完全一样。 I also added the app and e2e folders from https://github.com/angular/quickstart , which are referenced from the QuickStart. 我还从https://github.com/angular/quickstart添加了app和e2e文件夹,这些文件夹已从QuickStart中引用。

I then added 然后我加了

<my-app>Loading AppComponent content here ...</my-app>

to Index.cshtml . Index.cshtml I can compile and run the app without any errors. 我可以编译并运行该应用程序而不会出现任何错误。 But I still see 但我仍然看到

Loading AppComponent content here ...

when the page renders instead of seeing the following: 当页面呈现而不是看到以下内容时:

Hello Angular

Which is what should appear. 这应该出现。 The angular.io plunkr verifies this: https://embed.plnkr.co/?show=preview&show=app%2Fapp.component.ts . angular.io plunkr对此进行了验证: https ://embed.plnkr.co/?show = preview&show = app%2Fapp.component.ts。

Microsoft.TypeScript.Compiler , Microsoft.TypeScript.MSBuild and TypeScript 2 are all installed. Microsoft.TypeScript.CompilerMicrosoft.TypeScript.MSBuild和TypeScript 2都已安装。

This is just a basic, non modified asp.net mvc app to see if I can get Angular2 working. 这只是一个基本的,未经修改的asp.net mvc应用程序,以查看我是否可以使Angular2工作。

The asp.net mvc template may have a different folder/file structure than the asp.net core. asp.net mvc模板的文件夹/文件结构可能不同于asp.net核心。 So I'm not sure how angular2 knows there is an app folder. 所以我不确定angular2如何知道有一个应用程序文件夹。

Any ideas why this might not be working? 任何想法为什么这可能不起作用?

https://angular.io/docs/ts/latest/cookbook/visual-studio-2015.html is a horrible. https://angular.io/docs/ts/latest/cookbook/visual-studio-2015.html太可怕了。 firstly it is about asp.net 4.x, who is going to create new project with asp.net 4 today? 首先是关于asp.net 4.x,今天谁将要使用asp.net 4创建新项目?

If your answer is "I do", then more bad news coming, it never show you how to combine ng2 with asp.net core, check my solution. 如果您的回答是“我愿意”,那么更多的坏消息来了,它永远不会向您展示如何将ng2与asp.net核心结合起来,请检查我的解决方案。 https://github.com/Longfld/ASPNETCoreAngular2 https://github.com/Longfld/ASPNETCoreAngular2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM