Michael
Michael

Reputation: 13616

Why I get error when application starts?

I use angularjs version 1.6.4 in my project. I have this error in console debugger when my application starts:

http://errors.angularjs.org/1.6.4/$injector/nomod?p0=reports

Here is my main module:

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' })
    }]);

Here is reports module:

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

Here is reports controller:

(function () {
    "use strict";

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

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

Here how I load all the files dependency and module in my Layout page:

        @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")

Any idea why I get error above?

Upvotes: 0

Views: 34

Answers (2)

Sajeetharan
Sajeetharan

Reputation: 222522

Your main module is dependent on reports module, so load the reports module initially before loading main module.Change the order as follows,

 "~/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",  

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 691625

You're trying to add a controller to the reports module before you define the reports module.

Define the module first, then you can add controllers to it.

I.e. make sure the reports.module.js file is loaded before the reports.controller.js file, and not after.

Upvotes: 2

Related Questions