无法加载ngRoute模块

时间:2015-12-01 02:56:28

标签: javascript angularjs node.js angular-routing

我正在使用Angular的Node.js项目,我试图实现多个视图和路由。我已按照此处列出的说明安装angular-route.js文件和相关模块:

https://docs.angularjs.org/api/ngRoute

但我仍然在控制台中收到此错误:

Uncaught Error: [$injector:modulerr] Failed to instantiate module blogApp due to:
Error: [$injector:modulerr] Failed to instantiate module ngRoute due to:
Error: [$injector:nomod] Module 'ngRoute' 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.
http://errors.angularjs.org/1.3.20/$injector/nomod?p0=ngRoute

以下是与我的控制器和HTML文件相关的部分:

app.js

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

的index.html

<!DOCTYPE html>
<html ng-app="blogApp">
  <head>
    <title>Blog Posts</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- styles -->
    <link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="stylesheets/style.css" rel="stylesheet" media="screen">
  </head>
  <body ng-controller="postController">

   // page content

    <!-- scripts -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.20/angular.js"></script>
    <script src"https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.20/angular-route.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.2.min.js" type="text/javascript"></script>
    <script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="javascripts/app.js"></script>
  </body>
</html>

我是使用Angular和Node的新手,所以对此的任何想法都非常感谢!

2 个答案:

答案 0 :(得分:2)

这只是一个错字(缺少等号)。这一行:

<script src"https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.20/angular-route.js"></script>

应该是:

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.20/angular-route.js"></script>

答案 1 :(得分:0)

ngRoute脚本中包含一个非常小的拼写错误。您有src"https://而不是src="https://

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.20/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.20/angular-route.js"></script>
<script src="http://code.jquery.com/jquery-1.11.2.min.js" type="text/javascript"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js" type="text/javascript"></script>
<script src="javascripts/app.js"></script>

您可以通过检查开发人员工具并确保加载脚本而不会出错来调试这类问题。