ng-include目录无法正常工作

时间:2016-07-19 05:39:41

标签: angularjs

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
</script>

</head>

<body ng-app="myApp">


    <div ng-include="'table.html'"></div>



</body>
</html>



<table>
    hdjhfdjhhd
    <thead>
    <tr>
    <th>Name</th>
    <th>Gender </th>
    <th>Age</th>
    </tr>
    </thead>

</table>

ng-include无效。浏览器中无法显示任何内容。

2 个答案:

答案 0 :(得分:2)

创建一个控制器并附加到html,然后就可以了。

Menu.html

<html ng-app="myApp">
<head>
    <meta charset="utf-8"/>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
    </script>
    <script src="../js/app.js"></script>

</head>

<body>
<h1>Menu</h1>
<div ng-include="'table.html'"></div>
</body>
</html>

app.js

var app = angular.module('myApp', []);

app.controller('MyCtrl', function($scope) {
  // Empty
});

Table.html

<p>
    Table template
</p>

see the directory structure below

答案 1 :(得分:1)

html是不是只遵循我做的例子 https://plnkr.co/edit/CwTXcxTB90CfOgZ1ovKk?p=preview

<强>的index.html

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

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
   <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"> </script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <div ng-include="'table.html'"></div>
  </body>

</html>

<强> table.html

 <p>
    Hello Guys i am template2
    </p>