0

我正在为 AngularJS v1.6 应用程序设置路由,但遇到了一个小问题。

我收到以下错误,我似乎无法弄清楚出了什么问题。我希望你们能对我的错误有所了解。

Uncaught Error: [$injector:modulerr] <http://errors.angularjs.org/1.6.1/$injector/modulerr?p0=app&p1=Error%3A%20%…ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.1%2Fangular.min.js%3A21%3A332>)
    at angular.js:38
    at angular.js:4759
    at q (angular.js:357)
    at g (angular.js:4720)
    at eb (angular.js:4642)
    at c (angular.js:1838)
    at Mc (angular.js:1859)
    at pe (angular.js:1744)
    at angular.js:32977
    at HTMLDocument.b (angular.js:3314)

下面是我的代码:

应用程序.js;

(function () {
    "use strict";

    angular.module("app", [
        "ngRoute",
        "app.home",
        "app.products",
        "app.contact"
    ])

    .config(function ($routeProvider) {

        $routeProvider
            .when("/",
            {
                controller: "homeController",
                templateUrl: "app/components/home/home.html"
            })
            .when("/products",
            {
                controller: "productsController",
                templateUrl: "app/components/products/products.html"
            })
            .when("/contact",
            {
                controller: "contactController",
                templateUrl: "app/components/contact/contact.html"
            });
    });

})();

这是我的控制器之一(所有 3 个都相同)...

(function() {
    "use strict";

    angular
        .module("app.home", [])
        .controller("homeController", homeController);

    function homeController() {
        this.helloWorld = "Hello World";
    }

});
4

3 回答 3

1

链接到错误消息:

https://docs.angularjs.org/error/$injector/modulerr?p0=app&p1=undefined

使用 ngRoute

在 AngularJS 1.2.0 及更高版本中,ngRoute已移至其自己的模块。如果您在升级到 1.2.x 或更高版本后收到此错误,请确保您已安装ngRoute.

于 2017-01-09T06:39:46.377 回答
0

是的,这是我在重新审视我的应用程序后几秒钟内修复的一个错误。我的每个控制器都缺少 IIFY 末尾的括号。

于 2017-01-15T13:15:36.847 回答
0

我遇到了同样的问题。尝试在视图文件中包含使用 angular-route.js 的 ngRoute

于 2017-02-01T12:35:09.577 回答