【问题标题】:Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.7.9/$injector/moduler未捕获的错误:[$injector:modulerr] http://errors.angularjs.org/1.7.9/$injector/moduler
【发布时间】:2020-01-02 20:00:15
【问题描述】:

在加载我的应用程序时,我在控制台中收到上述错误。我的控制器如下所示。我是 Angular 新手,因此我们将不胜感激 我试图在这里将数据表导出到 excel 中。我认为问题出在 angular.module('myApp','datatables', 'datatables.buttons']) 将它们包含在模块中的正确方法是什么?

ViewCtrl.js

angular.module('myApp',['datatables', 'datatables.buttons'])
    .controller('ViewCtrl', function($scope, DTOptionsBuilder, DTColumnDefBuilder) {
       $scope.dtOptions = DTOptionsBuilder.newOptions()
        .withPaginationType('full_numbers')
        .withDisplayLength(2)
        .withDOM('pitrfl')
        .withButtons([{
                extend: 'excelHtml5',

            }
        ]);
 vm.dtColumnDefs = [
    DTColumnDefBuilder.newColumnDef(0),
    DTColumnDefBuilder.newColumnDef(1).notVisible(),
    DTColumnDefBuilder.newColumnDef(2).notSortable()
  ];
});

【问题讨论】:

  • 你能复制粘贴整个错误吗?通过删除注入的 DTOOptionsBuilder 和 DTColumnDefBuilder,然后注释掉变量,验证您是否可以使用空白控制器启动 angularjs。 vm.dtColumnDefs 和 $scope.dtOptions。在控制器中放置一个 console.log 声明(“耶!我成功了”)。如果你可以让 console.log 显示出来,那么注入的 ['datatables', 'datatables.buttons''] 可能不是你的问题。

标签: node.js angularjs excel angular-datatables


【解决方案1】:

验证控制台加载。如果 console.log 没有显示并且您仍然收到注入错误,那么您的问题很可能是 datatables 和 datatables.buttons。验证这些文件是否已添加到您的 index.html 文件中,位于该文件之前。

angular.module('myApp', ['datatables', 'datatables.buttons'])
.controller('ViewCtrl', function ($scope) {
    console.log("Code of awesomeness");
});

如果你发现你确实看到了 console.log("Code of awesomeness");那么您的 $inject 问题是 DTOptionsBuilder、DTColumnDefBuilder。验证拼写。

【讨论】:

  • 我将我的代码包含在已经有 DTOOptionsBuilder 和 DTColumnDefBuilder 的现有代码中,并且它工作正常。当我在 app.module 中包含没有 ['datatables', 'datatables.buttons''] 的作品时,我在控制台中收到以下错误
  • angular.js:15570 TypeError: DTOptionsBuilder.newOptions(...).withPaginationType(...).withDisplayLength(...).withDOM(...).withButtons 不是函数在新的 (app.bundle.js:3689) 在 Object.instantiate (angular.js:5158) 在 angular.js:11722 在 Object. (viewDirective.ts:410) 在 angular.js:1390在 Ba (angular.js:11269) 在 p (angular.js:10588) 在 g (angular.js:9835) 在 angular.js:9700 在 angular.js:10114 "" 但是上面的函数已经在代码中使用过了。我是否缺少包含任何 JS 的内容?
  • 我确实在凉亭组件中安装了以下软件包 datatables.net datatables.net-dt datatables.net-buttons-dt datatables.net-buttons
  • 所以 .withButtons 尚未使用,我将其作为我的代码的一部分。所以我错过了包含任何 JS 文件。我们在 gulp 中从 bower_components 获取所有包并将其复制到 vendor 文件夹。
猜你喜欢
  • 2015-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多