2016-01-29 88 views
0

我正在开发我的第一个小而简单的应用程序与平均堆栈,但我有一些角度问题(我正在学习它),我已经找到一个答案没有找到解决方案。 我有下面的文件在我的项目,但是当我去到本地主机:3000我收到此错误:无法实例化模块 - 角

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. 

我的文件:

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'); 
}); 

回答

1

router.js应该有角度脚本加载之后。因为它需要angular模块&其预先加载的对象。

此外,您还需要在应用程序中注入ngRoute模块,以确保路由引擎应该在那里。

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

脚本

<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>  
+0

你是对的,但我仍然得到同样的错误 – splunk

+0

@GreenMamba我可知道什么是'router.js'?并在控制台中获得哪些错误? –

+0

我试图创建一个导航菜单,当我点击一个链接(例如Alpi)时,它应该调用setRoute方法并在网页中插入内容(标题和正文)。 完整的错误信息在这里:http://justpaste.it/hiking-app-angular – splunk

相关问题