angular-datatables ReferenceError: $ is not defined using Dot net core angular 4 template

angular-datatables ReferenceError: $ is not defined using Dot net core angular 4 template

我使用 visual studio 模板创建了一个 Angular 4 with dot net core 应用程序。 我想在我的应用程序中使用数据表并尝试使用 https://l-lin.github.io/angular-datatables/#/getting-started 执行步骤 但我收到错误消息:ReferenceError: $ is not defined。 我尝试使用 import * as $ from "jquery";但是没有用。 请指教。谢谢。

您无法关注 https://l-lin.github.io/angular-datatables/#/getting-started 的 .Net Core - Angular 应用程序。该设置需要 .angular_cli.json,并且由于您没有使用 ng serve,它不会那样工作。

也许您可以在 ASP .NET index.cshtml 文件中添加 CDN .js 包:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" type="text/javascript"></script>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js" type="text/javascript"></script>

并在您的 _Layout.cshtml 文件中添加 css:

<link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" />

请检查并告诉我们是否可行。祝你好运。