简体   繁体   English

使用angularJS时出现未捕获的错误:[$ injector:modulerr]

[英]Uncaught Error: [$injector:modulerr] when using angularJS

I'm using angularJS in my application but when I add config section for routing I'm get this error : 我在应用程序中使用angularJS,但是当我添加配置部分进行路由时,出现此错误:

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.9/$injector/modulerr?p0=demoApp&p1=Error%3A…nts%2FGitHub%2FSirwanAfifi.github.io%2Fscripts%2Fangular.min.js%3A32%3A232)

this is my code : 这是我的代码:

var demoApp = angular.module('demoApp', []);

demoApp.config(function ($routeProvider) {
            $routeProvider
                .when('/',
                    {
                        controller: 'CustomerController',
                        templateUrl: 'views/view1.html'
                    })
                .when('/view1',
                    {
                        controller: 'CustomerController',
                        templateUrl: 'views/view1.html'
                    })
                .otherwise({redirectTo:'/'});
});

I found this answer but I'm not using angular-route.min.js , I just want to use simple route in my application. 我找到了这个答案,但是我没有使用angular-route.min.js ,我只想在应用程序中使用简单的路由。

Well, I agree with the rest of the comments - you definitely need ngRoute dependency and angular-route.js or angular-route.min.js file included. 好吧,我同意其余的意见-您确实需要ngRoute依赖项和包含angular-route.js或angular-route.min.js文件。 It's because $routeProvider is declared inside of those files. 这是因为$ routeProvider在这些文件中声明。 The idea of AngularJS team was to separate the different logic parts of the framework, make them independent and thus making possible to use some parts of the frameworks in your applications or frameworks as well as future ability to use it at the server side (Node.js environment). AngularJS团队的想法是将框架的不同逻辑部分分开,使其独立,从而使在应用程序或框架中使用框架的某些部分以及将来在服务器端使用它的能力成为可能(节点。 js环境)。 Some old previous versions didn't require to include separate files and dependencies. 某些较早的旧版本不需要包含单独的文件和依赖项。 For now that is obligatory. 目前,这是必须的。

需要向您的应用程序注入ngRoute

var demoApp = angular.module('demoApp', ['ngRoute']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM