Sirwan Afifi
Sirwan Afifi

Reputation: 10824

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 :

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.

Upvotes: 2

Views: 4354

Answers (2)

Rkn
Rkn

Reputation: 120

Need to inject ngRoute to your app

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

Upvotes: 0

Alexander Kalinovski
Alexander Kalinovski

Reputation: 1409

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. It's because $routeProvider is declared inside of those files. 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). Some old previous versions didn't require to include separate files and dependencies. For now that is obligatory.

Upvotes: 4

Related Questions