我使用 AngularJs 创建了一个简单的页面。当我尝试在 index.html 中包含 header.htm 时,浏览器中没有显示任何内容。
index.html
<html>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js">
</script>
<body>
<div ng-app="">
<div ng-include="'views/header.htm'"></div>
</div>
</body>
</html>
标题.htm
<h1>Header</h1>
最佳答案
您尚未显示您的文件夹结构以及 header.html
的定义。从下次开始尝试创建 MCVE .
我创建了一个fiddle展示它是如何工作的。
<div ng-controller="Ctrl">
<div ng-include ="'header.html'" onload='myFunction()'></div>
</div>
<!-- header.html -->
<script type="text/ng-template" id="header.html">
Content of Header html
</script>
function Ctrl($scope) {
$scope.myFunction = function() {
alert('header loaded');
}
}
关于javascript - ng-include 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44871305/