我有ASP.NET Core MVC Web应用程序,并且我想有一些要用Angular开发的页面(具有复杂的UI)。
例如,我有一个页面,该页面将在URL /customer/index
上显示客户列表(使用ASP.NET Core MVC完成的路由),而执行此操作的组件为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一样使用。
有什么建议吗?