Wednesday, 17 May 2017

AngularJs Error: [$injector:modulerr] by ngRoute?

Probably a dupicate (Failed to instantiate module error in Angular js) but the given measures (including ng-route in HTML didn't solve the problem).

This is the error:

Uncaught Error: [$injector:modulerr] Failed to instantiate module coursemate due to: Error: [$injector:nomod] Module 'coursemate' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

this is my app.js

var coursemate = angular.module('coursemate', ["ngRoute"]);
                
coursemate.config(function($routeProvider) {
        $routeProvider
    .when("/", {
        templateUrl : "view1.html"
    })
    .otherwise({
        redirectTo : '/';
    });
});

        
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

this is my index.html

<!DOCTYPE html>
<html lang="de" ng-app="coursemate">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>CourseMate</title>

    <base href="/CourseMate/" />

    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.0/css/font-awesome.min.css">
    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- Material Design Bootstrap -->
    <link href="css/mdb.min.css" rel="stylesheet">
    <!-- Your custom styles (optional) -->
    <link href="css/style.css" rel="stylesheet">
</head>
<body>

<ng-view>
</ng-view>
    
</body>


<!-- SCRIPTS -->
<!-- JQuery -->
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<!-- Bootstrap tooltips -->
<script type="text/javascript" src="js/tether.min.js"></script>
<!-- Bootstrap core JavaScript -->
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<!-- MDB core JavaScript -->
<script type="text/javascript" src="js/mdb.min.js"></script>
<!-- AngularJS reditect -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script>
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.1/angular-ui-router.js"></script>-->
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<script src="/app.js"></script>



</html>

I can not find my mistake as I don't think that I have initialized the app in a wrong way?



via Marius

No comments:

Post a Comment