Angular2 Visual Studio 2017 MVC:未捕获TypeError:System.config不是函数

时间:2017-11-24 20:36:43

标签: node.js asp.net-mvc angular visual-studio systemjs

我正在通过Visual Studio 2017 ASP.NET MVC构建Angular2 Web应用程序

我做的所有基本配置。

但是当我尝试构建应用程序时,它会抛出错误。

错误:

enter image description here

我很惊讶应用程序运行成功,有时会抛出此错误。

按照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>&copy; @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>

1 个答案:

答案 0 :(得分:-1)

您需要使用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>

通过这种方式,您可以确保它始终解析为应用程序路径的根目录,而不是某些fubfolder,如果您的路由更改为/ controller / action / something。

相关问题