badr aldeen
badr aldeen

Reputation: 470

Uncaught Error: [$injector:modulerr with angualrJs when i use routing

this is part of my problem = https://jsfiddle.net/2vrz38d6/ it contain just the js part open the console to see what i have

i get confused to solve this error
Error: $injector:modulerr Module Error

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.10/$injector/modulerr?p0=myApp&p1=Error%3A%…3A9641%2Fassets%2Fglobal%2Fplugins%2Fangularjs%2Fangular.min.js%3A38%3A435)

My Error happen with routing in angularJs the error which i took it is : my Error page here

my code is :

(function () {
    var MyApp = angular.module('myApp');


    MyApp.config(function ($routeProvider) {
        $routeProvider
            .when('/', {
                templateUrl: 'views/expenses.html',
                controller: 'CurriculumController'
            })



       .otherwise({
           redirectTo: '/'

       });

and the controller

        MyApp.controller('CurriculumController', ['$scope', '$rest', function ($scope, $rest) { 
//some stuf here 

for my script angular file : in the first i have this

 <script src="/assets/global/plugins/angularjs/angular.min.js"></script>

and in the middle of the project i have the file of my angular apps

<script src="/Scripts/NGModel/Curriculum/Curriculum.js"></script>

and after that the file of the routing part for angularjs

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>

Upvotes: 0

Views: 1848

Answers (4)

Arjun
Arjun

Reputation: 516

you should add your dependencies in to the module like this

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

Upvotes: 0

Sudhansu Choudhary
Sudhansu Choudhary

Reputation: 3360

you have to include angular-route.js.

Dependency injection would be angular.module('myApp', ['ngRoute']);

EDIT as the inclusion of Angular libraries were updated in the OP's problem statement :-

Replace

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script> with

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.10/angular-route.min.js"></script> as you have mentioned in comments that you are using v1.3.10

And as @Garrett has suggested, add,

.otherwise("/");

Upvotes: 1

Garrett
Garrett

Reputation: 709

As people above have suggested, you need to include that file, but you also need to make sure that you are doing it in the correct order as well in your index file. I suppose trying a different set of CDNs wouldn't hurt either.

<script src="https://code.angularjs.org/1.3.15/angular.min.js"></script>
<script src="https://code.angularjs.org/1.3.15/angular-route.min.js"></script>

Also, in your route configurations, just a mention that you can do this as well for your otherwise:

MyApp.config(function ($routeProvider) {
    $routeProvider
    .when('/', {
        templateUrl: 'views/expenses.html',
        controller: 'CurriculumController'
    })
    .otherwise("/");
});

Upvotes: 1

Fals
Fals

Reputation: 6839

You will need to make this work:

1) Add the angular-route file: Include the file below the angular.js

 <script src="angular-route.js">

2) Inject the ng-route at the definition of your app:

angular.module('myApp', ['ng-route']);

Upvotes: 0

Related Questions