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.

Community
  • 1
  • 1
Sirwan Afifi
  • 10,654
  • 14
  • 63
  • 110

2 Answers2

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.

Alexander Kalinovski
  • 1,409
  • 1
  • 13
  • 19
  • I saw this type of code in a video called "AngularJS Fundamentals in 60-ish Minutes", so he used older version of angular library. – Sirwan Afifi Jan 19 '14 at 14:33
  • 2
    here, he mentioned about that problem http://weblogs.asp.net/dwahlin/archive/2013/08/14/angularjs-routing-changes.aspx – Sirwan Afifi Jan 19 '14 at 14:40
0

Need to inject ngRoute to your app

var demoApp = angular.module('demoApp', ['ngRoute']);
Rkn
  • 122
  • 2
  • 11