angular.js - angular使用ng-include,為什么生成不了html代碼
問題描述
今天在學(xué)習(xí)angularJS的時(shí)候,視頻講到ng-include的用法。說白了也就是把通用的html代碼提取到一個(gè)html文件里面再include進(jìn)去而已。
但是我在index.html引入同一目錄下的product-title.html時(shí),卻不顯示product-title.html里面的內(nèi)容。
angular版本是1.4.8
index.html:
<h3 ng-include='’product-title.html’'></h3>
product-title.html:
{{product.name}}<em class='pull-right'>{{product.price | currency}}</em>
看調(diào)試界面生成的是:
<!-- ngInclude: a.html -->
這么一句話。
問題解答
回答1:是因?yàn)闆]有把頁面放在http服務(wù)器上運(yùn)行。
回答2:是不是路徑有問題?你看一下product-title.html和index.html是不是同一級(jí)別。
回答3:瀏覽器中看看,html是404還是? 即確認(rèn)文件路徑~
回答4:ng-include的值必須是一個(gè)變量,不能是文件名。將文件路徑賦值給一個(gè)變量,再ng-include=’變量名’
