我正在通过 Visual Studio 2017 ASP.NET MVC 构建 Angular2 Web 应用程序
我所做的所有基本配置。
但是当我尝试构建应用程序时,它会抛出错误。
错误:
令我惊讶的是,有时应用程序成功运行,但有时会抛出此错误。
已关注 this link进行快速设置
package.json、tsconfig.json 和 systemjs.config.js 复制自quickstart
_Layout.cshtml
<!DOCTYPE html>
<html>
<head>
<script src="/node_modules/core-js/client/shim.min.js"></script>
<script src="/node_modules/zone.js/dist/zone.js"></script>
<script src="/node_modules/systemjs/dist/system.src.js"></script>
<script src="/system.config.js"></script>
<script>
System.import('app').catch(function (err) { console.error(err); });
</script>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>
Index.cshtml
@{
ViewBag.Title = "Home Page";
}
<app-root>Loading...</app-root>
最佳答案
您需要使用 Url.Content()
解析脚本的路径:
<script src="@Url.Content("~/node_modules/core-js/client/shim.min.js")"></script>
<script src="@Url.Content("~/node_modules/zone.js/dist/zone.js")"></script>
<script src="@Url.Content("~/node_modules/systemjs/dist/system.src.js")"></script>
<script src="@Url.Content("~/system.config.js")"></script>
这样,如果您的路线更改为/controller/action/something,您可以确保它始终解析为应用程序路径的根目录,而不是某些 fubfolder。
关于node.js - Angular2 Visual Studio 2017 MVC : Uncaught TypeError: System. 配置不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47479713/