0

I'm developing my first little and easy app with MEAN stack but I have some problem with angular (I'm learning it) and I've searched for an answer without finding a solution. I have the files below in my project but when I go to localhost:3000 I receive this error:

Failed to instantiate module hiking-app due to:
[$injector:nomod] Module 'hiking-app' 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.

My files:

ROUTER.JS

angular.module("hiking-app",[]).
config(function($routeProvider)
{
    $routeProvider.
    when('/alpi', 
    {
        template : 'partials/basic-template.html', controller:AlpiCtrl
    }).
    when('/ande', 
    {
        template : 'partials/basic-template.html', controller:AndeCtrl
    }).
    when('/dolomiti', 
    {
        template : 'partials/basic-template.html', controller:DolomitiCtrl
    }).

    otherwise({redirectTo:'/home', template:'partials/home.html'});
});

function MainCtrl($scope, $location)
{
    $scope.setRoute = function(route)
    {
        $location.path(route);
    }
}

function AlpiCtrl($scope)
{
    $scope.title = "ALPI";
    $scope.body = "test ";
}

function AndeCtrl($scope)
{
    $scope.title = "ANDE";
    $scope.body = "test ";
}

function DolomitiCtrl($scope)
{
    $scope.title = "DOLOMITI";
    $scope.body = "test ";
}

INDEX.HTML

<html ng-app="hiking-app">
    <head>
    <link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css"/>
    <link rel="stylesheet" href="css/main.css" />
    <script src="app.js"></script>
    <script src="node_modules/angular/angular.js"></script>
    <script src="node_modules/angular-route/angular-route.js"></script>
    <script src="router.js"></script>    

    </head>

      <div id="header"><img src="img/hiking-header.png" /></div>
    <body ng-controller="MainCtrl">
        <nav class="navbar navbar-default" ng-controller="NavigationController">
        <table id="menutable">
            <tr>
            <td><a ng-click="setRoute('alpi')">Alpi</a></td>
                <td><a ng-click="setRoute('ande')">Ande</a></td>
                <td><a ng-click="setRoute('dolomiti')">Dolomiti</a></td>
                <td><a ng-href="{{himalaya}}">Himalaya</a></td>
            <td><input type="button" value="REGISTRATI" id="btnreg"></input></td>
            <td><input type="button" value="LOGIN" id="btnlogin"></input></td>
           </tr>
        </table>
            </nav>
        <div class="container">
        <div ng-view></div> 
        </div>
    </nav>
 </body>   
</html>

BASIC-TEMPLATE.HTML

<h1>{{title}}</h1>
<p>{{body}}</p>

APP.JS

var express = require('express'),
app = express();
var server = require('http').createServer(app);
var mongoose = require('mongoose');

app.use('/app', express.static(__dirname));
app.use('/node_modules', express.static(__dirname + "/node_modules"));
app.use('/img',express.static(__dirname + "/img"));
app.use('/css',express.static(__dirname + "/css"));

server.listen(3000);

mongoose.connect('mongodb://127.0.0.1/mountains', function(err){
    if(err){
        console.log(err);
    } else{
        console.log('Connected to mongodb!');
    }
});

app.get('/', function(req, res){
    res.sendFile(__dirname + '/index.html');
});
splunk
  • 6,435
  • 17
  • 58
  • 105

1 Answers1

1

router.js should be there after angular scripts are loaded. As it need angular modules & its object pre-loaded.

Also you need to inject ngRoute module inside your application to make sure route engine should be there.

angular.module("hiking-app",['ngRoute'])

Scripts

<script src="/app.js"></script>
<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angular-route/angular-route.js"></script>
<script src="/router.js"></script>    
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299