[英]How the right way to use ng-include
我是Angular.js的初學者,並且在指令ng-include
方面遇到了一些問題。
我想在index.html
顯示header.html
內容
好吧,這是我的樹例子:
myapp
. public
. . lib
. . . angular.js
. . .
. header.html
. index.html
Header.html代碼:
<h1>Hello Angular</h1>
Index.html代碼:
<html ng-app>
<head>
<meta charset="utf-8">
<script src="public/lib/angular.js"></script>
</head>
<body>
<ng-include src="'header.html'"></ng-include>
</body>
</html>
當我運行index.html
,我有這樣的事情:
<!-- ngInclude: undefined -->
我不確定是否有包含其他模板的ng-include
標簽。 我們通常這樣做
<div ng-include src="'header.html'"></div>
您是通過Web服務器訪問應用程序還是通過file://
protocol訪問該文件? 在后一種情況下,由於瀏覽器的安全限制,它將無法工作。 解決方案是安裝Apache或Nginx並通過http://localhost/myapp/index.html
等方式訪問應用程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.