Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将Angular与.ASP.NET核心MVC应用程序混合使用?_Asp.net_Angular_Asp.net Mvc_Asp.net Core - Fatal编程技术网

如何将Angular与.ASP.NET核心MVC应用程序混合使用?

如何将Angular与.ASP.NET核心MVC应用程序混合使用?,asp.net,angular,asp.net-mvc,asp.net-core,Asp.net,Angular,Asp.net Mvc,Asp.net Core,我有ASP.NET核心MVC web应用程序,我想用Angular开发一些页面(具有复杂的UI) 例如,我有一个页面,在URL上显示客户列表(使用ASP.NET Core MVC完成的路由):/customer/index,执行此操作的组件是app show customers 另一个页面(/customer/edit/42)用于使用组件app edit customer编辑客户 这两个组件都插入到*.cshtml视图中 我执行以下操作来引导它 platformBrowserDynamic(pr

我有ASP.NET核心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));
它对我有用

我遇到的问题是,当在页面上找不到模块时,其中一个引导调用失败。它仍然有效,但在控制台中给出了错误

错误:选择器“应用程序编辑客户”与任何元素都不匹配

例如,当我打开
/customer/index
以显示所有客户时,
EditCustomerModule
引导抛出错误,反之亦然

我理解这是因为
/customer/index
上不存在
应用程序编辑客户
组件

我觉得我在那里做错了什么,但我不知道到底是什么。当您只希望使用Angular开发某些页面时,通常如何将Angular与ASP.NET核心MVC应用程序结合使用

当使用AngularJS时,这不是一个问题,但我觉得Angular2不能与ASP.NET核心MVC混合使用,应该像SPA一样使用


有什么建议吗?

如果可以的话,我强烈建议您使用一个.NET API和一个完整的前端。这可能需要更多的工作,但使用API扩展应用程序会更容易。这不是答案,但这里有人提出了一种将ASP.NET MVC与Angular混合使用的方法: