簡體   English   中英

如何正確使用ng-include

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM