为什么我在应用程序启动时出错?

时间:2017-12-25 09:43:52

标签: angularjs

我在我的项目中使用angularjs版本1.6.4。 我的应用程序启动时,我在控制台调试器中出现此错误:

http://errors.angularjs.org/1.6.4/ $注射器/ NOMOD?P0 =报告

这是我的主要模块:

angular.module('main', ['ngRoute', 'ngAnimate', 'ngTouch', 'ngResource', 'reports', 'ui.grid'])
    .config(['$routeProvider', function ($routeProvider) {
        $routeProvider.
            when('/reports', { templateUrl: 'app/ReportTrafficDepart/App/Reports/templates/reports.html', controller: 'reportsController' })
    }]);

这是报告模块:

angular.module('reports', ['ngAnimate', 'ngTouch', 'ngResource', 'ui.grid']);

这是报告控制器:

(function () {
    "use strict";

    angular.module("reports").controller('reportsController');

    function reportsController() {
        var t = "test";
    }
})();

这里我如何在Layout页面中加载所有文件依赖项和模块:

        @Scripts.Render(
                 "~/Scripts/angular.min.js",
                 "~/Scripts/angular-route.min.js",
                 "~/Scripts/angular-touch.min.js",
                 "~/Scripts/angular-resource.min.js",
                 "~/Scripts/ui-grid.min.js",
                 "~/Scripts/xml2json.js",
                 "~/Scripts/angular-animate.min.js",

                 //main
                 "~/app/ReportTrafficDepart/App/Main/main.module.js",
                 //Reports        
                 "~/app/ReportTrafficDepart/App/Reports/controller/reports.controller.js",
                 "~/app/ReportTrafficDepart/App/Reports/reports.module.js")

知道为什么我上面会出错吗?

2 个答案:

答案 0 :(得分:2)

您正在尝试将控制器添加到报告模块,然后才能定义报告模块。

首先定义模块,然后可以向其添加控制器。

即。确保reports.module.js文件在<{strong> reports.controller.js文件之前加载,而不是之后。

答案 1 :(得分:1)

您的主模块依赖于 reports 模块,因此请先加载报告模块,然后再加载 main module 。更改订单,如下所示,

 "~/Scripts/angular.min.js",
 "~/Scripts/angular-route.min.js",
 "~/Scripts/angular-touch.min.js",
 "~/Scripts/angular-resource.min.js",
 "~/Scripts/ui-grid.min.js",
 "~/Scripts/xml2json.js",
 "~/Scripts/angular-animate.min.js",
 "~/app/ReportTrafficDepart/App/Reports/reports.module.js"
 "~/app/ReportTrafficDepart/App/Reports/controller/reports.controller.js",
 "~/app/ReportTrafficDepart/App/Main/main.module.js",