您的位置:首页技术文章
文章详情页

angular.js - angular使用ng-include,为什么生成不了html代码

【字号: 日期:2024-03-18 17:31:40浏览:83作者:猪猪

问题描述

今天在学习angularJS的时候,视频讲到ng-include的用法。说白了也就是把通用的html代码提取到一个html文件里面再include进去而已。

但是我在index.html引入同一目录下的product-title.html时,却不显示product-title.html里面的内容。

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>

看调试界面生成的是:

<!-- ngInclude: a.html -->

这么一句话。

问题解答

回答1:

是因为没有把页面放在http服务器上运行。

回答2:

是不是路径有问题?你看一下product-title.html和index.html是不是同一级别。

回答3:

浏览器中看看,html是404还是? 即确认文件路径~

回答4:

ng-include的值必须是一个变量,不能是文件名。将文件路径赋值给一个变量,再ng-include=’变量名’

标签: HTML