2

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.

2
  • Possible duplicate: stackoverflow.com/questions/18287482/… Commented Jan 19, 2014 at 14:20
  • From looking at this, you didn't inject ngRoute into your module dependencies Commented Jan 19, 2014 at 14:22

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I saw this type of code in a video called "AngularJS Fundamentals in 60-ish Minutes", so he used older version of angular library.
here, he mentioned about that problem weblogs.asp.net/dwahlin/archive/2013/08/14/…
0

Need to inject ngRoute to your app

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.