Uncaught Error: [$injector:modulerr] - Angular ng-include

Uncaught Error: [$injector:modulerr] - Angular ng-include

我正在使用 ng-include 将一些 HTML 页附加到 AngularJS 中的一个 HTML 页。

找到Main.html页面代码

<!DOCTYPE html>
<html ng-app="Test">

<head>
<link rel="stylesheet" href ="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
</head>

<body ng-controller="userController">

<div class="container">
  <div ng-include="'test1.htm'"></div>
  <div ng-include="'test2.htm'"></div>
</div>


</body>
</html>

test1.html代码

<!DOCTYPE html>
<html>
<head>
</head>
<body>
Full Name: 
</body>
</html>

我的代码似乎没有问题。但是当我在浏览器中加载它时,没有任何显示并且我收到控制台错误提示,

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.26/$injector/modulerr?p0=Test&p1=Error%3A%2…gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.26%2Fangular.min.js%3A18%3A387)

请帮我解决问题。

您必须在 head 标记中包含 'angular 路由 java 脚本文件。 像这样,

<head>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.route.js"></script>
</head>

错误在这里

<html ng-app="Test">

您必须定义一个新模块才能将其用作应用程序

类似的东西

MainModule.js

    var app =angular.module("myApp",[]);
    app.controller("myCTRL"["$scope",function($scope){

    }]);

然后将该 js 文件包含到您的项目中以使用它 那样

    <!DOCTYPE html>
    <html ng-app="myApp">

    <head>
            <link rel="stylesheet" href ="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
            <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>    
            <script src="assets/js/MainModule.js"></script>
</head>

    <body ng-controller="myCTRL">

    <div class="container">
      <div ng-include="'test1.htm'"></div>
      <div ng-include="'test2.htm'"></div>
    </div>


    </body>
    </html>