无法加载ngRoute模块

Unable to load ngRoute module

本文关键字:模块 ngRoute 加载      更新时间:2023-09-26

我正在开发一个使用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的新手,所以非常感谢对此的任何想法!

这只是一个拼写错误(缺少等号)。此行:

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

ngRoute的include脚本中有一个非常小的拼写错误。你有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>

您可以通过检查开发人员工具并确保加载的脚本没有错误来调试这类问题。