简体   繁体   English

如何使用 Visual Studio 2019 在 ASP.NET MVC 中集成 Angular 8 项目

[英]How to integrate Angular 8 project in ASP.NET MVC using Visual Studio 2019

I created an Angular 8 project using CLI and now I want to use this project in ASP.NET MVC using Visual Studio 2019.我使用 CLI 创建了一个 Angular 8 项目,现在我想使用 Visual Studio 2019 在 ASP.NET MVC 中使用这个项目。

To answer your question as you asked it: To integrate an Angular 8 app into an ASP.NET MVC project, you'll have to use the CLI to generate the app in a folder inside of the MVC project.要按照您的要求回答您的问题:要将 Angular 8 应用程序集成到 ASP.NET MVC 项目中,您必须使用 CLI 在 MVC 项目内的文件夹中生成应用程序。 You would then need to set up routing in such a way that Angular knows when you are requesting an Angular component vs when you are requesting an MVC view.然后,您需要以 Angular 知道您何时请求 Angular 组件和何时请求 MVC 视图的方式设置路由。 You would also need to remember to compile your Angular app before deploying.您还需要记住在部署之前编译您的 Angular 应用程序。 And don't deploy your Angular source files.并且不要部署您的 Angular 源文件。

That being said, the better approach would be to use the Visual Studio Angular app with.Net Core Web Api project template which does much of the boring work for you.话虽如此,更好的方法是使用 Visual Studio Angular 应用程序和 .Net Core Web Api 项目模板,它为您完成了很多无聊的工作。 While it is technically possible to integrate Angular into an MVC application, it's probably a better idea to not mix the two and rather use a Web API backend and do ALL of the front end stuff in Angular. While it is technically possible to integrate Angular into an MVC application, it's probably a better idea to not mix the two and rather use a Web API backend and do ALL of the front end stuff in Angular. I do however understand that it's not always that simple, especially when working with existing systems which need to be migrated bit-by-bit.然而,我确实明白这并不总是那么简单,尤其是在使用需要逐位迁移的现有系统时。

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

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