asp.net - 如何将 Angular 与 .ASP.NET Core MVC 应用程序混合使用?
问题描述
我有 ASP.NET Core MVC Web 应用程序,我想用 Angular 开发一些页面(带有复杂的 UI)。
例如,我有一个页面将在 URL: 上显示客户列表(使用 ASP.NET Core MVC 完成的路由)/customer/index
,以及执行此操作的组件是app-show-customers
.
另一个页面 ( /customer/edit/42
) 用于编辑使用组件的客户app-edit-customer
。
这两个组件都插入到*.cshtml
视图中。
我执行以下操作来引导它
platformBrowserDynamic(providers).bootstrapModule(ShowCustomersModule)
.catch(err => console.log(err));
platformBrowserDynamic(providers).bootstrapModule(EditCustomerModule)
.catch(err => console.log(err));
这个对我有用。
我遇到的问题是在页面上找不到模块时引导调用失败之一。它仍然有效,但在控制台中给出错误。
错误:选择器“app-edit-customer”不匹配任何元素
例如,当我打开/customer/index
以显示所有客户时,EditCustomerModule
引导会引发错误,反之亦然。
我知道这是因为该app-edit-customer
组件不存在于/customer/index
.
我觉得我在那里做错了什么,但我不知道到底是什么。当您只想使用 Angular 开发一些页面时,您通常如何将 Angular 与 ASP.NET Core MVC 应用程序一起使用。
使用 AngularJS 时,这不是问题,但我感觉 Angular 2 不能与 ASP.NET Core MVC 混合使用,应该像 SPA 一样使用。
有什么建议么?