[英]Angular2 Visual Studio 2017 MVC: Uncaught TypeError: System.config is not a function
I am building Angular2 web application through Visual Studio 2017 ASP.NET MVC 我正在通过Visual Studio 2017 ASP.NET MVC构建Angular2 Web应用程序
All the basic configuration I did. 我所做的所有基本配置。
But when I am trying to build app then it is throwing an error. 但是,当我尝试构建应用程序时,它将引发错误。
Error: 错误:
I am surprised some time application run successfully and sometimes it throws this error. 我很惊讶一段时间应用程序成功运行,有时会引发此错误。
Following this link to do quick setup 点击此链接进行快速设置
package.json, tsconfig.json and systemjs.config.js copied from quickstart 从快速入门复制的package.json,tsconfig.json和systemjs.config.js
_Layout.cshtml _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 Index.cshtml
@{
ViewBag.Title = "Home Page";
}
<app-root>Loading...</app-root>
You need to resolve the path to your script with Url.Content()
: 您需要使用
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>
This way you ensure it is always resolving to the root of your applications path and not some fubfolder if your Route changes to /controller/action/something. 这样,如果您的Route更改为/ controller / action / something,则可以确保它始终解析到应用程序路径的根目录,而不是fubfolder。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.