未捕获错误:[$ injector:modulerr] - Angular ng-include

时间:2015-03-09 03:30:26

标签: javascript jquery html angularjs angularjs-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>

我的代码似乎没有错。但是当我在浏览器中加载它时,没有显示任何内容,我得到控制台错误,

  

未捕获错误:[$ injector:modulerr]   http://errors.angularjs.org/1.2.26/ $注射器/ modulerr P0 =测试与安培; P1 =错误%3A%2 ... gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.26%2Fangular.min.js%3A18%3A387)

请帮我解决这个问题。

2 个答案:

答案 0 :(得分:1)

错误就在这里

<html ng-app="Test">

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

类似的东西

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>

答案 1 :(得分:-1)

您必须在头标记中包含'angular route java script file。 像这样,

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